Tworzenie evaluation.

This commit is contained in:
Jan Nowak 2021-05-13 00:15:26 +02:00
parent 590c961196
commit 7fd26e40e1
4 changed files with 87 additions and 12 deletions

View File

@ -25,3 +25,5 @@ COPY ./dlgssdpytorch.py ./
RUN chmod +x dlgssdpytorch.py
COPY ./create_dataset.py ./
RUN chmod +x create_dataset.py
COPY ./evaluation.py ./
RUN chmod +x evaluation.py

39
Jenkinsfile_evaluation Normal file
View File

@ -0,0 +1,39 @@
pipeline {
agent any
parameters {
buildSelector(
defaultSelector: lastSuccessful(),
description: 'Which build to use for copying artifacts',
name: 'BUILD_SELECTOR')
}
stages {
stage('checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://git.wmi.amu.edu.pl/s426206/ium_426206.git']]])
}
}
stage('Copy artifact') {
steps {
copyArtifacts filter: 'model.pt', fingerprintArtifacts: false, projectName: 's426206-training', selector: buildParameter('BUILD_SELECTOR')
}
}
stage('docker') {
steps {
script {
def img = docker.build('rokoch/ium:01')
img.inside {
sh 'chmod +x evaluation.py'
sh 'python3 ./evaluation.py >>> metryki.txt'
}
}
}
}
stage('end') {
steps {
//Zarchiwizuj wynik
archiveArtifacts 'model.pt'
}
}
}
}

View File

@ -101,15 +101,8 @@ for epoch in range(n_epochs):
print(f"[{epoch+1}] Training loss: {training_loss:.3f}\t Validation loss: {validation_loss:.3f}")
# 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))
torch.save(model, 'model.pt')
torch.save({
'model_state_dict': model.state_dict(),
'optimizer_state_dict': optimizer.state_dict(),
'loss': lr,
}, 'model.pt')

41
evaluation.py Normal file
View File

@ -0,0 +1,41 @@
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")