question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when get intermediate output

See original GitHub issue

Hello, 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:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
JonathanSumcommented, Oct 17, 2020

@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()

1reaction
lukemelascommented, Apr 20, 2020

Use .extract_features(), as in the README:

from efficientnet_pytorch import EfficientNet
model = EfficientNet.from_pretrained('efficientnet-b0')

# ... image preprocessing as in the classification example ...
print(img.shape) # torch.Size([1, 3, 224, 224])

features = model.extract_features(img)
print(features.shape) # torch.Size([1, 1280, 7, 7])
Read more comments on GitHub >

github_iconTop Results From Across the Web

Tensorflow/Keras: Error when calculating intermediate ...
I have a network network , which is already trained and written with tensorflow . In a later step of my computation I...
Read more >
000207: Cannot create intermediate output <value>.
As the tool executes, it creates intermediate output. When a problem occurs while creating this output, it is possible that a dataset with...
Read more >
After clearing intermediate result, re-extract particles report ...
Hi, After I clear intermediate result of all job, I can't extract particles. It report an error as the follwing: [CPU: 252.9 MB]...
Read more >
Solved: Get tensor from intermediate layers
Convert my PB model to XML with mo_tf.py selecting as output the layers I want as output. However, I get the error mo.utils.error.Error:...
Read more >
Is it possible to start TensorFlow from an intermediate layer?
Hello, I was wondering Lets say if I get the output of an intermediary layer, would it be possible to feed the data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found