TypeError: 'NoneType' object is not callable while use the model

I’m using PyTorch for training GCN, I have a simple model that saved using this command:

torch.save(MyNet().state_dict(), PATH)

Then I load it by doing the following:

model = MyNet()
model.load_state_dict(torch.load(PATH))
model.eval()

But then when I tried to input the data as follows:

output = model(dataset)

I got this error for the previous line:

TypeError: 'NoneType' object is not callable

I don’t know what’s the reason for that, could you please help me?

Could you add some debug statements to your code and check, if the model variable was replaced somewhere?

model = MyNet()
print(model)
[...]
print(model)
output = model(dataset)

I guess that model was initially a valid object, but might have been replaced accidentally with None.

When I tried to print the model after model = MyNet() I got the model printed well, but then when I tried to print it before output = model(dataset) I got None

What could be the problem?

It seems your code is overwriting the model variable at one point.
Search for all usages of model and make sure it’s not replaced by a None value.