keisen / tf-keras-vis

Neural network visualization toolkit for tf.keras
https://keisen.github.io/tf-keras-vis-docs/
MIT License
311 stars 45 forks source link

TypeError: '<=' not supported between instances of 'int' and 'str' #80

Open JackDanHollister opened 2 years ago

JackDanHollister commented 2 years ago

Hello all,

wondered if anyone has encounted the error:

TypeError: '<=' not supported between instances of 'int' and 'str'

`%%time
from tensorflow.keras import backend as K
from tf_keras_vis.saliency import Saliency
# from tf_keras_vis.utils import normalize

# Create Saliency object.
saliency = Saliency(model,
                    model_modifier=replace2linear,
                    clone=True)

# Generate saliency map
saliency_map = saliency(score, X)

## Since v0.6.0, calling `normalize()` is NOT necessary.
#saliency_map = normalize(saliency_map)

# Render
f, ax = plt.subplots(nrows=1, ncols=3, figsize=(12, 4))
for i, title in enumerate(image_titles):
    ax[i].set_title(title, fontsize=16)
    ax[i].imshow(saliency_map[i], cmap='jet')
    ax[i].axis('off')
plt.tight_layout()
plt.show()

TypeError                                 Traceback (most recent call last)
<timed exec> in <module>

/usr/local/lib/python3.8/dist-packages/tf_keras_vis/saliency.py in __call__(self, score, seed_input, smooth_samples, smooth_noise, keepdims, gradient_modifier, training, normalize_map, unconnected_gradients)
     98             grads = [g / smooth_samples for g in total]
     99         else:
--> 100             grads = self._get_gradients(seed_inputs, scores, gradient_modifier, training,
    101                                         unconnected_gradients)
    102         # Visualizing

/usr/local/lib/python3.8/dist-packages/tf_keras_vis/saliency.py in _get_gradients(self, seed_inputs, scores, gradient_modifier, training, unconnected_gradients)
    115             outputs = self.model(seed_inputs, training=training)
    116             outputs = listify(outputs)
--> 117             score_values = self._calculate_scores(outputs, scores)
    118         grads = tape.gradient(score_values,
    119                               seed_inputs,

/usr/local/lib/python3.8/dist-packages/tf_keras_vis/__init__.py in _calculate_scores(self, outputs, score_functions)
     86         score_values = (func(output) for output, func in zip(outputs, score_functions))
     87         score_values = (self._mean_score_value(score) for score in score_values)
---> 88         score_values = list(score_values)
     89         return score_values
     90 

/usr/local/lib/python3.8/dist-packages/tf_keras_vis/__init__.py in <genexpr>(.0)
     85     def _calculate_scores(self, outputs, score_functions):
     86         score_values = (func(output) for output, func in zip(outputs, score_functions))
---> 87         score_values = (self._mean_score_value(score) for score in score_values)
     88         score_values = list(score_values)
     89         return score_values

/usr/local/lib/python3.8/dist-packages/tf_keras_vis/__init__.py in <genexpr>(.0)
     84 
     85     def _calculate_scores(self, outputs, score_functions):
---> 86         score_values = (func(output) for output, func in zip(outputs, score_functions))
     87         score_values = (self._mean_score_value(score) for score in score_values)
     88         score_values = list(score_values)

/usr/local/lib/python3.8/dist-packages/tf_keras_vis/utils/scores.py in __call__(self, output)
     99             raise ValueError("`output` ndim must be 2 or more (batch_size, ..., channels), "
    100                              f"but was {output.ndim}")
--> 101         if output.shape[-1] <= max(self.indices):
    102             raise ValueError(
    103                 f"Invalid index value. indices: {self.indices}, output.shape: {output.shape}")

TypeError: '<=' not supported between instances of 'int' and 'str'
`