Skip to content

ValueError: not enough values to unpack (expected 4, got 2) for GradCAM++ #17

@r0cketr1kky

Description

@r0cketr1kky

Model: Alexnet
Dataset: CIFAR-10

The code works well with layer_name='features' but I get this error when I change it to layer_name='classifier'

Code:

# GRADCAM++ 
image_path = 'xyz'
image = load_image(image_path)
norm_image = apply_transforms(image, size=32)

model_dict = dict(arch=model, layer_name='classifier_0', input_size=(32, 32))
  
gradcampp = GradCAMpp(model_dict)
output = gradcampp(norm_image)
visualize(norm_image, output)

Error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-63-fed255ab9edc> in <module>()
      7 
      8 gradcampp = GradCAMpp(model_dict)
----> 9 output = gradcampp(norm_image)
     10 visualize(norm_image, output)

1 frames
<ipython-input-46-e7d860e12ca6> in __call__(self, input_, class_idx, retain_graph)
     70 
     71     def __call__(self, input_, class_idx=None, retain_graph=False):
---> 72         return self.forward(input_, class_idx, retain_graph)

<ipython-input-49-d221b5d1444c> in forward(self, input_image, class_idx, retain_graph)
     32         gradients = self.gradients['value']
     33         activations = self.activations['value']
---> 34         b, k, u, v = gradients.size()
     35 
     36         alpha_num = gradients.pow(2)

ValueError: not enough values to unpack (expected 4, got 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions