I am trying to implement GradCAM for Efficientnet-B5. Could you please help debug the following error?

username: Akshay_A_J
cooked: <p>ENet = EfficientNet.from_pretrained(‘efficientnet-b5’).to(device)<br>
in_features = ENet._fc.in_features<br>
ENet._fc = nn.Linear(in_features= in_features, out_features=2)<br>
ENet = ENet.to(device)</p>
<p>class ENET(nn.Module):<br>
def <strong>init</strong>(self):<br>
super(ENET, self).<strong>init</strong>()</p>
<pre><code>    self.ENet = ENet

    #disect the network to access its last convolutional layer
    self.head0 = nn.Sequential(*list(self.ENet.children())[:4])
    #self.head = nn.Sequential(*list(self.ENet.children())[2:4])
    
    self.BN =  nn.BatchNorm2d(2048, eps=0.001, momentum=0.010000000000000009, affine=True, track_running_stats=True)

    self.tail = nn.Sequential(*list(self.ENet.children())[-4:])

    # placeholder for the gradients
    self.gradients = None

# hook for the gradients of the activations
def activations_hook(self, grad):
    self.gradients = grad
    
def forward(self, *x):
    x = self.head0(x)

    #x = self.head(x)

    #register the hook
    h = x.register_hook(self.activations_hook)
    
    x = self.BN(x)

    x = x.view((1, -1))

    x = self.tail(x)

    return x

# method for the gradient extraction
def get_activations_gradient(self):
    return self.gradients

# method for the activation exctraction
def get_activations(self, x):
    return self.head0(x)
</code></pre>
<p>model = ENET()</p>
<h1>set the evaluation mode</h1>
<p>model.eval()</p>
<h1>get the image from the dataloader</h1>
<p>img, _ = next(iter(train_loader))<br>
img = img.to(device)<br>
print(img.shape)</p>
<h1>get the most likely prediction of the model</h1>
<p>pred = model(img)</p>
<h2>OUTPUT:<br>
torch.Size([1, 3, 299, 299])</h2>
<p>AttributeError                            Traceback (most recent call last)<br>
 in ()<br>
9 print(img.shape)<br>
10 # get the most likely prediction of the model<br>
—&gt; 11 pred = model(img)</p>
<p>8 frames<br>
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)<br>
725             result = self._slow_forward(*input, **kwargs)<br>
726         else:<br>
–&gt; 727             result = self.forward(*input, **kwargs)<br>
728         for hook in itertools.chain(<br>
729                 _global_forward_hooks.values(),</p>
<p> in forward(self, *x)<br>
26<br>
27     def forward(self, *x):<br>
—&gt; 28         x = self.head0(x)<br>
29<br>
30         <span class="hashtag">#x</span> = self.head(x)</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)<br>
725             result = self._slow_forward(*input, **kwargs)<br>
726         else:<br>
–&gt; 727             result = self.forward(*input, **kwargs)<br>
728         for hook in itertools.chain(<br>
729                 _global_forward_hooks.values(),</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py in forward(self, input)<br>
115     def forward(self, input):<br>
116         for module in self:<br>
–&gt; 117             input = module(input)<br>
118         return input<br>
119</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)<br>
725             result = self._slow_forward(*input, **kwargs)<br>
726         else:<br>
–&gt; 727             result = self.forward(*input, **kwargs)<br>
728         for hook in itertools.chain(<br>
729                 _global_forward_hooks.values(),</p>
<p>/usr/local/lib/python3.6/dist-packages/efficientnet_pytorch/utils.py in forward(self, x)<br>
268<br>
269     def forward(self, x):<br>
–&gt; 270         x = self.static_padding(x)<br>
271         x = F.conv2d(x, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups)<br>
272         return x</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)<br>
725             result = self._slow_forward(*input, **kwargs)<br>
726         else:<br>
–&gt; 727             result = self.forward(*input, **kwargs)<br>
728         for hook in itertools.chain(<br>
729                 _global_forward_hooks.values(),</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/padding.py in forward(self, input)<br>
19<br>
20     def forward(self, input: Tensor) -&gt; Tensor:<br>
—&gt; 21         return F.pad(input, self.padding, ‘constant’, self.value)<br>
22<br>
23     def extra_repr(self) -&gt; str:</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in _pad(input, pad, mode, value)<br>
3549                 _pad, (input,), input, pad, mode=mode, value=value)<br>
3550     assert len(pad) % 2 == 0, ‘Padding length must be divisible by 2’<br>
-&gt; 3551     assert len(pad) // 2 &lt;= input.dim(), ‘Padding length too large’<br>
3552     if mode == ‘constant’:<br>
3553         return _VF.constant_pad_nd(input, pad, value)</p>
<p>AttributeError: ‘tuple’ object has no attribute ‘dim’</p>