Skip to content

inconsistent tensor size #6

@jackowang

Description

@jackowang

Hi @greydanus

I'm not sure whether it is caused by the maxpooling in my network.
After feature extraction by CNN (B,C,14,14),
My final layer : nn.MaxPool2d(14,1,0) -> view(output.size(0), self.num_classes) where self.num_classes=8

prob_outputs_dog = Variable(torch.zeros(1,8)) ; prob_outputs_dog.data[:,dog] += 1
prob_inputs_dog = eb.excitation_backprop(model, inputs, prob_outputs_dog, contrastive=False)

And the error I got is

RuntimeError Traceback (most recent call last)
in ()
9
10
---> 11 prob_inputs_chair = eb.excitation_backprop(model, inputs, prob_outputs_chair, contrastive=False)

~/anaconda2/envs/exbp/lib/python3.6/site-packages/excitationbp-0.1-py3.6.egg/excitationbp/utils.py in excitation_backprop(model, inputs, prob_outputs, contrastive, target_layer)
45 if not contrastive:
46 outputs = model(inputs)
---> 47 return torch.autograd.grad(top_h_, target_h_, grad_outputs=prob_outputs)[0]
48
49 pos_evidence = torch.autograd.grad(top_h_, contr_h_, grad_outputs=prob_outputs.clone())[0]

~/anaconda2/envs/exbp/lib/python3.6/site-packages/torch/autograd/init.py in grad(outputs, inputs, grad_outputs, retain_graph, create_graph, only_inputs, allow_unused)
156 return Variable._execution_engine.run_backward(
157 outputs, grad_outputs, retain_graph,
--> 158 inputs, only_inputs, allow_unused)
159
160 if not torch._C._autograd_init():

~/anaconda2/envs/exbp/lib/python3.6/site-packages/excitationbp-0.1-py3.6.egg/excitationbp/functions/eb_convNd.py in backward(self, grad_output)
65 norm_factor, = _view3d(norm_factor)
66
---> 67 grad_output /= norm_factor + 1e-20 # normalize
68 ### stop EB-SPECIFIC CODE ###
69

~/anaconda2/envs/exbp/lib/python3.6/site-packages/torch/tensor.py in idiv(self, other)
348
349 def idiv(self, other):
--> 350 return self.div_(other)
351 itruediv = idiv
352

RuntimeError: inconsistent tensor size, expected r_ [1 x 8], t [1 x 8] and src [1 x 8 x 14 x 14] to have the same number of elements, but got 8, 8 and 1568 elements respectively at /opt/conda/conda-bld/pytorch_1518243271935/work/torch/lib/TH/generic/THTensorMath.c:1063

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions