Forward not implemented error

username: Jaideep_Valani
cooked: <p>Hi experts<br>
please help over the below error that i get</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py in forward(self, input)<br>
90     def forward(self, input):<br>
91         for module in self._modules.values():<br>
—&gt; 92             input = module(input)<br>
93         return input<br>
94</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in <strong>call</strong>(self, *input, **kwargs)<br>
491             result = self._slow_forward(*input, **kwargs)<br>
492         else:<br>
–&gt; 493             result = self.forward(*input, **kwargs)<br>
494         for hook in self._forward_hooks.values():<br>
495             hook_result = hook(self, input, result)</p>
<p>/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py in forward(self, input)<br>
90     def forward(self, input):<br>
91         for module in self._modules.values():<br>
—&gt; 92             input = module(input)</p>
<p><strong>Model details: it is sequence of two modules</strong></p>
<ol>
<li>
<p>Efficient Net<br>
Sequential(<br>
(0): Sequential(<br>
(0): Conv2dStaticSamePadding(<br>
3, 48, kernel_size=(3, 3), stride=(2, 2), bias=False<br>
(static_padding): ZeroPad2d(padding=(0, 1, 0, 1), value=0.0)<br>
)<br>
(1): BatchNorm2d(48, eps=0.001, momentum=0.010000000000000009, affine=True, track_running_stats=True)<br>
(2): ModuleList(<br>
(0): MBConvBlock(<br>
(_depthwise_conv): Conv2dStaticSamePadding(<br>
48, 48, kernel_size=(3, 3), stride=[1, 1], groups=48, bias=False<br>
(static_padding): ZeroPad2d(padding=(1, 1, 1, 1), value=0.0)<br>
)<br>
(_bn1): BatchNorm2d(48, eps=0.001, momentum=0.010000000000000009, affine=True, track_running_stats=True)<br>
(_se_reduce): Conv2dStaticSamePadding(<br>
48, 12, kernel_size=(1, 1), stride=(1, 1)<br>
(static_padding): Identity()<br>
)<br>
(_se_expand): Conv2dStaticSamePadding(<br>
12, 48, kernel_size=(1, 1), stride=(1, 1)<br>
(static_padding): Identity()<br>
)<br>
(_project_conv): Conv2dStaticSamePadding(<br>
48, 24, kernel_size=(1, 1), stride=(1, 1), bias=False<br>
(static_padding): Identity()<br>
)<br>
(_bn2): BatchNorm2d(24, eps=0.001, momentum=0.010000000000000009, affine=True, track_running_stats=True)<br>
)<br>
(1): MBConvBlock(<br>
(_depthwise_conv): Conv2dStaticSamePadding(<br>
24, 24, kernel_size=(3, 3), stride=(1, 1), groups=24, bias=False<br>
(static_padding): ZeroPad2d(padding=(1, 1, 1, 1), value=0.0)<br>
)<br>
(_bn1): BatchNorm2d(24, eps=0.001, momentum=0.010000000000000009, affine=True, track_running_stats=True)<br>
(_se_reduce): Conv2dStaticSamePadding(<br>
24, 6, kernel_size=(1, 1), stride=(1, 1)<br>
(static_padding): Identity()<br>
)<br>
(_se_expand): Conv2dStaticSamePadding(<br>
6, 24, kernel_size=(1, 1), stride=(1, 1)<br>
(static_padding): Identity()<br>
)<br>
(_project_conv): Conv2dStaticSamePadding(<br>
24, 24, kernel_size=(1, 1), stride=(1, 1), bias=False<br>
(static_padding): Identity()<br>
) … and so on…</p>
</li>
<li>
<p>Customheadeff(<br>
(head): Sequential(<br>
(0): AdaptiveConcatPool2d(<br>
(ap): AdaptiveAvgPool2d(output_size=1)<br>
(mp): AdaptiveMaxPool2d(output_size=1)<br>
)<br>
(1): Flatten()<br>
(2): BatchNorm1d(4096, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(3): Dropout(p=0.25)<br>
(4): Linear(in_features=4096, out_features=2048, bias=True)<br>
(5): LeakyReLU(negative_slope=0.01, inplace)<br>
(6): BatchNorm1d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(7): Dropout(p=0.5)<br>
(8): Linear(in_features=2048, out_features=1024, bias=True)<br>
)<br>
(arc_margin): ArcMarginProduct()<br>
)</p>
</li>
</ol>

username: ptrblck
cooked: <p>How did you define the current model?<br>
It seems as if you just stacked some modules in an <code>nn.Sequential</code> block.<br>
Note that this might work for very simple models, but might fail for others.<br>
E.g. if the original <code>forward</code> method contains some other functions than just calling all submodules sequentially, it won’t work out of the box.</p>

username: Jaideep_Valani
cooked: <p>ok<br>
this is how models are stacked up<br>
Sequential(<br>
(0): Sequential(<br>
(0): EfficientNet(<br>
(_conv_stem): Conv2dStaticSamePadding(<br>
3, 48, kernel_size=(3, 3), stride=(2, 2), bias=False<br>
(static_padding): ZeroPad2d(padding=(0, 1, 0, 1), value=0.0)<br>
)<br>
(_bn0): BatchNorm2d(48, eps=0.001, momentum=0.010000000000000009, affine=True, track_running_stats=True)<br>
(_blocks): ModuleList(<br>
----so on<br>
(1): Customheadeff(<br>
(head): Sequential(<br>
(0): AdaptiveConcatPool2d(<br>
(ap): AdaptiveAvgPool2d(output_size=1)<br>
(mp): AdaptiveMaxPool2d(output_size=1)<br>
)<br>
(1): Flatten()<br>
(2): BatchNorm1d(4096, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(3): Dropout(p=0.25)<br>
(4): Linear(in_features=4096, out_features=2048, bias=True)<br>
(5): ReLU(inplace)<br>
(6): BatchNorm1d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(7): Dropout(p=0.5)<br>
(8): Linear(in_features=2048, out_features=1024, bias=True)<br>
)<br>
(arc_margin): ArcMarginProduct()<br>
)<br>
)</p>

username: Jaideep_Valani
cooked: <p>This should provide you sufficient info to you help debug this issue.Input size(1,3,224,224)<br>
Module class<br>
!pip install efficientnet_pytorch<br>
from efficientnet_pytorch import EfficientNet<br>
model = EfficientNet.from_pretrained(‘efficientnet-b5’, num_classes=5)</p>
<pre><code class="lang-auto">class efficient(nn.Module):
    
    
  
    def __init__(self,m):
        super().__init__()
        
        l=nn.Sequential()
        fc=nn.Sequential()
        l.add_module('conv_stem',m._conv_stem)
        l.add_module('_bn0',m._bn0)
        l.add_module('_blocks',m._blocks)
        l.add_module('_conv_head',m._conv_head)
        
        self.add_module('feature',l)
        fc.add_module('_bn1',m._bn1)
        fc.add_module('_fc',m._fc)
        
        self.add_module('fc',fc)
         
         
        
         
    def forward(self, x):
         
        x1=self.feature(x)
        x1= self.fc(x1)
        #x1=self._blocks(x1)
        #x1=self._conv_head(x1)
        #x1=self._bn1(x1)
        #x = x.view(x.size(0), -1)
         
        #x=self.l1(x)
       # x = self.x_unet(x, self.sfs[0].features)
        #x1 = self.fc(x)
        return x1
</code></pre>
<p>m=efficient(model)<br>
m(x)</p>
<p><strong>Gives Not implemented error</strong><br>
result = self.forward(*input, **kwargs)<br>
494         for hook in self._forward_hooks.values():<br>
495             hook_result = hook(self, input, result)</p>
<p>/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)<br>
90     def forward(self, input):<br>
91         for module in self._modules.values():<br>
—&gt; 92             input = module(input)<br>
93         return input<br>
94</p>
<p>/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in <strong>call</strong>(self, *input, **kwargs)<br>
491             result = self._slow_forward(*input, **kwargs)<br>
492         else:<br>
–&gt; 493             result = self.forward(*input, **kwargs)<br>
494         for hook in self._forward_hooks.values():<br>
495             hook_result = hook(self, input, result)</p>
<p>/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)<br>
90     def forward(self, input):<br>
91         for module in self._modules.values():<br>
—&gt; 92             input = module(input)<br>
93         return input<br>
94</p>
<p>/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in <strong>call</strong>(self, *input, **kwargs)<br>
491             result = self._slow_forward(*input, **kwargs)<br>
492         else:<br>
–&gt; 493             result = self.forward(*input, **kwargs)<br>
494         for hook in self._forward_hooks.values():<br>
495             hook_result = hook(self, input, result)</p>
<p>/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in forward(self, *input)<br>
86             registered hooks while the latter silently ignores them.<br>
87         “”"<br>
—&gt; 88         raise NotImplementedError</p>