Forward not implemented error

Can some one please help me with this baffling error

This should provide you sufficient info to you help debug this issue.Input size(1,3,224,224)
Module class
!pip install efficientnet_pytorch
from efficientnet_pytorch import EfficientNet
model = EfficientNet.from_pretrained(‘efficientnet-b5’, num_classes=5)

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)
       
        return x1

m=efficient(model)
m(x)

Gives Not implemented error
result = self.forward(*input, **kwargs)
494 for hook in self._forward_hooks.values():
495 hook_result = hook(self, input, result)

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
90 def forward(self, input):
91 for module in self._modules.values():
—> 92 input = module(input)
93 return input
94

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
491 result = self._slow_forward(*input, **kwargs)
492 else:
–> 493 result = self.forward(*input, **kwargs)
494 for hook in self._forward_hooks.values():
495 hook_result = hook(self, input, result)

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
90 def forward(self, input):
91 for module in self._modules.values():
—> 92 input = module(input)
93 return input
94

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
491 result = self._slow_forward(*input, **kwargs)
492 else:
–> 493 result = self.forward(*input, **kwargs)
494 for hook in self._forward_hooks.values():
495 hook_result = hook(self, input, result)

/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py in forward(self, *input)
86 registered hooks while the latter silently ignores them.
87 “”"
—> 88 raise NotImplementedError

l.add_module(’_blocks’,m._blocks) this was giving an error… As per networ architecture it is a ModuleList object changing this to sequential helped overcome the issue
l.add_module('_blocks',nn.Sequential(*m._blocks))

1 Like