Trying to load model and switch to eval

In my script the model successfully trains and I save it at the end. When I try to load and evaluate it this is what happens:

Traceback (most recent call last):
  File ".\", line 139, in <module>
    gru_outputs, targets, gru_sMAPE = evaluate(gmodel, X_test, Y_test, label_scalars)
  File ".\", line 115, in evaluate
AttributeError: 'NoneType' object has no attribute 'eval'

This is the last portion of the code:

def evaluate(model, X_test, Y_test, label_scalars):
    outputs = []
    targets = []
    start_time = time.clock()
    for i in X_test.keys():
        inp = torch.from_numpy(np.array(X_test[i]))
        labs = torch.from_numpy(np.array(Y_test[i]))
        h = model.init_hidden(inp.shape[0])
        out, h = model(, h)
    print("Evaluation Time: {}".format(str(time.clock()-start_time)))
    sMAPE = 0
    for i in range(len(outputs)):
        sMAPE += np.mean(abs(outputs[i]-targets[i])/(targets[i]+outputs[i])/2)/len(outputs)
    print("sMAPE: {}%".format(sMAPE*100))
    return outputs, targets, sMAPE

lr = 0.002

#Gru_model = train(train_loader, lr)

gmodel = torch.load('./grunet.pkl')

gru_outputs, targets, gru_sMAPE = evaluate(gmodel, X_test, Y_test, label_scalars)

What does print(gmodel) return after the torch.load call?
Based on the error it seems it’s None, which indicates the loading fails somehow.

1 Like