# a deep copy of weights for the best performing model
best_model_wts = copy.deepcopy(model.state_dict())
# initialize best loss to a large value
best_loss=float('inf')
# main loop
.
.
.
# store best model
if val_loss < best_loss:
best_loss = val loss
best_model_wts = copy.deepcopy(model.state_dict())
# store weights into a local file
torch.save(model.state_dict(), path2weights)
print("Copied best model weights!")
'머신러닝 > Pytorch' 카테고리의 다른 글
define the optimizer and the learning rate schedule (0) | 2021.01.06 |
---|---|
visualize the filters of the first CNN layer (0) | 2021.01.06 |
Storing and loading models (0) | 2020.12.31 |
model summary (0) | 2020.12.31 |
pytorch 1.7.1 + cuda 11.0 + cudnn 8.0.5.39 on windows (0) | 2020.12.14 |