You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a tf 2.10 3DConv ANN with multiple regression outputs (model architecture at the end). I am attempting to use this package to generate gradcam++ heatmaps and I am getting the following error:
classRegressionScore(Score):
"""A score function that collects the scores from model output which is for regression """def__init__(self, target_values) ->None:
""" Args: target_values: A list of ints/floats. Raises: ValueError: When target_values is None or an empty list. """super().__init__('RegressionScore')
self.target_values=target_values#listify(target_values, return_empty_list_if_none=False)ifNoneinself.target_values:
raiseValueError(f"Can't accept None. target_values: {target_values}")
iflen(self.target_values) ==0:
raiseValueError(f"`indices` is required. target_values: {target_values}")
def__call__(self, output) ->tf.Tensor:
ifoutput.ndim<2:
raiseValueError("`output` ndim must be 2 or more (batch_size, ..., channels), "f"but was {output.ndim}")
ifoutput.shape[-1] <=max(self.target_values):
raiseValueError(
f"Invalid index value. target_values: {self.target_values}, output.shape: {output.shape}")
target_values=self.target_valuesprint(target_values.shape)
print(output[0].shape)
score=tf.math.abs(1.0/ (target_values-output[0]))
print(score)
returnscore
The offending line is grads = tape.gradient(score_values, penultimate_output, unconnected_gradients=unconnected_gradients). I have confirmed that score_values is a list of positive valued tensors and that penultimate_output is the output of the last conv layer.
Even using CategoricalScore on 5 sample videos I get the same error:
According to https://www.tensorflow.org/api_docs/python/tf/UnconnectedGradients, this is intended behavior to show that the source and target are unconnected and therefore have 0 gradients. It might be useful to wrap the gradients call in a try block and raise an exception with this information.
I'm not sure why my source and target are unconnected, going to keep digging.
I have a tf 2.10 3DConv ANN with multiple regression outputs (model architecture at the end). I am attempting to use this package to generate gradcam++ heatmaps and I am getting the following error:
I am using a custom Score class: RegressionScore:
The offending line is
grads = tape.gradient(score_values, penultimate_output, unconnected_gradients=unconnected_gradients)
. I have confirmed that score_values is a list of positive valued tensors and that penultimate_output is the output of the last conv layer.Even using CategoricalScore on 5 sample videos I get the same error:
The text was updated successfully, but these errors were encountered: