42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import torch
|
|
import numpy as np
|
|
from datetime import datetime
|
|
import torch.nn as nn
|
|
import torch.optim as optim
|
|
#from torch.utils.data import Dataset, TensorDataset, DataLoader
|
|
|
|
class LayerLinearRegression(nn.Module):
|
|
def __init__(self):
|
|
super().__init__()
|
|
# Instead of our custom parameters, we use a Linear layer with single input and single output
|
|
self.linear = nn.Linear(1, 1)
|
|
|
|
def forward(self, x):
|
|
# Now it only takes a call to the layer to make predictions
|
|
return self.linear(x)
|
|
|
|
checkpoint = torch.load('model.pt')
|
|
|
|
model = LayerLinearRegression()
|
|
optimizer = optim.SGD(model.parameters(), lr=checkpoint['loss'])
|
|
|
|
model.load_state_dict(checkpoint['model_state_dict'])
|
|
optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
|
|
|
|
model.eval()
|
|
|
|
now = datetime.now()
|
|
print("\n-----------{}-----------".format(now.strftime("%d/%m/%Y, %H:%M:%S")))
|
|
# Checks model's parameters
|
|
print("Model's state_dict:")
|
|
for param_tensor in model.state_dict():
|
|
print(param_tensor, "\t", model.state_dict()[param_tensor])
|
|
|
|
# Print optimizer's state_dict
|
|
print("Optimizer's state_dict:")
|
|
for var_name in optimizer.state_dict():
|
|
print(var_name, "\t", optimizer.state_dict()[var_name])
|
|
#print("Mean squared error for training: ", np.mean(losses))
|
|
#print("Mean squared error for validating: ", np.mean(val_losses))
|
|
print("----------------------\n")
|