Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

AttributeError: 'EBP_conv2dBackward' object has no attribute 'apply' #9

Open
vinutah opened this issue Mar 11, 2020 · 0 comments
Open

Comments

@vinutah
Copy link

vinutah commented Mar 11, 2020

Hi,

I seem to have Attribute Errors on a few examples.
for examples like:

from torchray.attribution.common import Probe, get_module
from torchray.attribution.excitation_backprop import ExcitationBackpropContext
from torchray.attribution.excitation_backprop import gradient_to_contrastive_excitation_backprop_saliency
from torchray.benchmark import get_example_data, plot_example

# Obtain example data.
model, x, category_id, _ = get_example_data()

# Contrastive excitation backprop.
input_layer = get_module(model, 'features.9')
contrast_layer = get_module(model, 'features.30')
classifier_layer = get_module(model, 'classifier.6')

input_probe = Probe(input_layer, target='output')
contrast_probe = Probe(contrast_layer, target='output')

with ExcitationBackpropContext():
    y = model(x)
    z = y[0, category_id]
    classifier_layer.weight.data.neg_()
    z.backward()

    classifier_layer.weight.data.neg_()

    contrast_probe.contrast = [contrast_probe.data[0].grad]

    y = model(x)
    z = y[0, category_id]
    z.backward()

saliency = gradient_to_contrastive_excitation_backprop_saliency(input_probe.data[0])

input_probe.remove()
contrast_probe.remove()

# Plots.
plot_example(x, saliency, 'contrastive excitation backprop', category_id)
>>> torch.__version__
'1.4.0'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-f8f5c1aa6dfa> in <module>
     27     y = model(x)
     28     z = y[0, category_id]
---> 29     z.backward()
     30 
     31 saliency = gradient_to_contrastive_excitation_backprop_saliency(input_probe.data[0])

~/anaconda3/lib/python3.7/site-packages/torch/tensor.py in backward(self, gradient, retain_graph, create_graph)
    193                 products. Defaults to ``False``.
    194         """
--> 195         torch.autograd.backward(self, gradient, retain_graph, create_graph)
    196 
    197     def register_hook(self, hook):

~/anaconda3/lib/python3.7/site-packages/torch/autograd/__init__.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)
     97     Variable._execution_engine.run_backward(
     98         tensors, grad_tensors, retain_graph, create_graph,
---> 99         allow_unreachable=True)  # allow_unreachable flag
    100 
    101 

AttributeError: 'EBP_conv2dBackward' object has no attribute 'apply'
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant