Description
#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)
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 ...