Thanks for your reply.
To clarify my question, first I open two terminal, and I define a simple class named BasicNN in the first terminal like below.
class simple(nn.Module):
def init(self):
super(simple, self).init()
self.net = nn.Linear(28 * 28, 2)
def forward(self, x):
x = np.array(x)
x = torch.from_numpy(x)
x = Variable(x)
x = x.view(1,1,28,28)
batch_size = x.size(0)
x = x.view(batch_size, -1)
output = self.net(x.float())
return out
model = simple()
torch.save(model,‘model.pkl’)
Then, I open a new terminal(or in another .py file), I want to load the model.
simple_model = torch.load(‘model.pkl’)
I get AttributeError : No module named simple.
But If I save and load a pretrained model like torchvision.models.vgg16, there is no such error. So I want to know whether I can change the forward function after I run model = torchvision.models.vgg16(pretrained=False)