The code below calculates the MSE and MAE values but I have an issue where the values for MAE and MSE don’t get stored at each epoch in store_MAE and store MSE. It seems to use the values of the last epoch only. Any idea what i need to do in the code to save the total values for each epoch i hope this make since
# logging:
loss = torch.mean((preds - targets)**2)
count_error = torch.abs(preds - targets).mean()
mean_test_error += count_error
writer.add_scalar('test_loss', loss.item(), global_step=global_step)
writer.add_scalar('test_count_error', count_error.item(), global_step=global_step)
global_step += 1
store_MAE = 0
store_MSE = 0
mean_test_error = mean_test_error / len(loader_test)
store_MAE += mean_test_error
mse = math.sqrt(loss / len(loader_test))
store_MSE +=mse
print("Test count error: %f" % mean_test_error)
print("MSE: %f" % mse)
if mean_test_error < best_test_error:
best_test_error = mean_test_error
torch.save({'state_dict':model.state_dict(),
'optimizer_state_dict':optimizer.state_dict(),
'globalStep':global_step,
'train_paths':dataset_train.files,
'test_paths':dataset_test.files},checkpoint_path)
print("MAE Total: %f" % store_MAE)
print("MSE Total: %f" % store_MSE)
model_mae= store_MAE /epoch
model_mse= store_MSE /epoch
print("Model MAE: %f" % model_mae)
print("Model MSE: %f" % model_mse)