Skip to content

integrated grad fails silently when input dtype is not float #138

@SeppeDeWinter

Description

@SeppeDeWinter

Report

The crested.tl._explainer.integrated_grad function will fail silently (producing 0 as output)
when the data type of the input is not a floating point.

The functions: crested.tl._explainer.saliency_map and crested.tl._explainer.smoothgrad at least give some warning.

import keras
import crested
import numpy as np
from crested.utils._seq_utils import one_hot_encode_sequence
from crested.tl._explainer import integrated_grad, saliency_map, smoothgrad
import random

model_path, output_names_biccn = crested.get_model("DeepBICCN")
model_biccn = keras.models.load_model(model_path)

random.seed(123)
oh = one_hot_encode_sequence("".join(random.choices(["A", "C", "G", "T"], k=model_biccn.input[0].shape[1]))).astype(np.uint8)

integrated_grad(oh, model_biccn, 1).sum()
#0

saliency_map(oh, model_biccn, 1).sum()
#WARNING:tensorflow:The dtype of the watched tensor must be floating (e.g. tf.float32), got tf.uint8 
#AttributeError: 'NoneType' object has no attribute 'numpy'

smoothgrad(oh, model_biccn, 1).sum()
#InvalidArgumentError: cannot compute AddV2 as input #1(zero-based) was expected to be a uint8 tensor but is a float tensor [Op:AddV2] name

Version information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions