You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def forword(self, x):
x = self.model.forward(x)
print(x.shape)
if name=="main":
model = myModel()
x = torch.randn(1,3,32,32)
model.forword(x)
I get the error: TypeError: forward() takes 1 positional argument but 2 were given
when I set the self.model = nn.Sequential(*list(base_model.children())[:2], *list(base_model.children())[2][:38])
It works !
Why and how to fix it...
Thank you very much ...
The text was updated successfully, but these errors were encountered:
If you need to prune just the last layers to use it as features extractor this seems a duplicate of this issue that was solved with this PR by nwschurink
Use EfficientNet.extract_endpoints(). It returns the intermediate values of the neural network before each reduction in image size (224 × 224 → 112 × 112, etc.).
#coding:utf8
import torch
from efficientnet_pytorch import EfficientNet
import torch.nn as nn
class myModel():
def init(self):
base_model = EfficientNet.from_pretrained(model_name="efficientnet-b5", weights_path="efficientnet-b5-b6417697.pth")
#self.model = nn.Sequential(*list(base_model.children())[:2], *list(base_model.children())[2][:38])
self.model = nn.Sequential(*list(base_model.children())[:6])
self.model.eval()
#print(self.model)
if name=="main":
model = myModel()
x = torch.randn(1,3,32,32)
model.forword(x)
I get the error: TypeError: forward() takes 1 positional argument but 2 were given
when I set the self.model = nn.Sequential(*list(base_model.children())[:2], *list(base_model.children())[2][:38])
It works !
Why and how to fix it...
Thank you very much ...
The text was updated successfully, but these errors were encountered: