Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Tensor' object has no attribute 'ndim' #102

Open
EnalisUs opened this issue Sep 1, 2023 · 1 comment
Open

'Tensor' object has no attribute 'ndim' #102

EnalisUs opened this issue Sep 1, 2023 · 1 comment

Comments

@EnalisUs
Copy link

EnalisUs commented Sep 1, 2023

why this wrong
%%time

from tf_keras_vis.gradcam_plus_plus import GradcamPlusPlus

Create GradCAM++ object

gradcam = GradcamPlusPlus(model,
model_modifier=model_modifier,
clone=False)
score = CategoricalScore([1, 1,1])

Generate heatmap with GradCAM++

cam = gradcam(score, images, penultimate_layer=-1)

Since v0.6.0, calling normalize() is NOT necessary.

cam = normalize(cam)

Render

f, ax = plt.subplots(nrows=1, ncols=3, figsize=(12, 4))
for i, title in enumerate(image_titles):
heatmap = np.uint8(cm.jet(cam[i])[..., :3] * 255)
ax[i].set_title(title, fontsize=16)
ax[i].imshow(images[i])
ax[i].imshow(heatmap, cmap='jet', alpha=0.5)
ax[i].axis('off')
plt.tight_layout()
plt.savefig('/content/gradcam_plus_plus.png')
plt.show()

@EnalisUs
Copy link
Author

EnalisUs commented Sep 1, 2023

outputs = model(seed_inputs, training=training)
93 outputs, penultimate_output = outputs[:-1], outputs[-1]
---> 94 score_values = self._calculate_scores(outputs, scores)
95 grads = tape.gradient(score_values,
96 penultimate_output,

4 frames
/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/ops.py in getattr(self, name)
441 np_config.enable_numpy_behavior()
442 """)
--> 443 self.getattribute(name)
444
445 @staticmethod

AttributeError: 'Tensor' object has no attribute 'ndim'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant