Can't load the saved model in PyTorch

20 Views Asked by At

Hello i’m new in using PyTorch bcs my assignment

i had my model saved and load but the error wasn’t the same like when i run it first. The error was 7,5% but when i rerun the error has changed to 9%. Can someone help me? this is my code

model.load_state_dict(torch.load("model.pth")['model'])`

loss_fn = nn.MSELoss(reduction="mean")
optimizer = optim.Adam(model.parameters(), lr=learning_rate, weight_decay=weight_decay)
optimizer.load_state_dict(torch.load("model.pth")['optimizer'])

opt = Optimization(model=model, loss_fn=loss_fn, optimizer=optimizer)
opt.train(train_loader, val_loader, batch_size=batch_size, n_epochs=n_epochs, n_features=input_dim)
opt.plot_losses()

predictions, values = opt.evaluate(
    test_loader_one,
    batch_size=1,
    n_features=input_dim
)
0

There are 0 best solutions below