Error when get intermediate output
See original GitHub issueHello, I’m trying to get intermediate output from Pytorch like this:
model = EfficientNet.from_pretrained('efficientnet-b0')
features = nn.Sequential(*list(model.children())[:-1])
x = torch.rand((4,3,224,224))
y = features(x)
And Colab throws me the error
NotImplementedError Traceback (most recent call last) <ipython-input-26-17722b8cd4a4> in <module>() 2 features = nn.Sequential(*list(model.children())[:-1]) 3 x = torch.rand((4,3,224,224)) ----> 4 y = features(x)
3 frames /usr/local/lib/python3.6/dist-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)
/usr/local/lib/python3.6/dist-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
/usr/local/lib/python3.6/dist-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)
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in forward(self, *input) 86 registered hooks while the latter silently ignores them. 87 “”" —> 88 raise NotImplementedError 89 90 def register_buffer(self, name, tensor):
NotImplementedError:
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
@lukemelas I think we should be allowed to access the model layer by indexing to apply hook to access the intermediate layers rather than a .extract_features()
Use
.extract_features()
, as in the README: