2021-06-20 15:04:51 +02:00
|
|
|
import torch
|
|
|
|
import torchvision
|
2021-06-15 01:36:18 +02:00
|
|
|
import torchvision.transforms as transforms
|
2021-06-20 15:04:51 +02:00
|
|
|
import torch.nn as nn
|
|
|
|
import torch.nn.functional as F
|
|
|
|
import torch.optim as optim
|
|
|
|
import numpy as np
|
|
|
|
from matplotlib.pyplot import imshow
|
|
|
|
import os
|
|
|
|
import PIL
|
|
|
|
import numpy as np
|
|
|
|
from matplotlib.pyplot import imshow
|
|
|
|
import neural_network
|
|
|
|
from matplotlib.pyplot import imshow
|
2021-06-15 01:36:18 +02:00
|
|
|
|
|
|
|
|
2021-06-20 15:04:51 +02:00
|
|
|
# wcześniej grader.py
|
2021-06-15 01:36:18 +02:00
|
|
|
# Get accuracy for neural_network model 'network_model.pth'
|
|
|
|
def NN_accuracy():
|
|
|
|
# Create the model
|
2021-06-20 15:04:51 +02:00
|
|
|
net = neural_network.Net()
|
2021-06-15 01:36:18 +02:00
|
|
|
|
|
|
|
# Load state_dict
|
2021-06-20 15:04:51 +02:00
|
|
|
neural_network.load_network_from_structure(net)
|
2021-06-15 01:36:18 +02:00
|
|
|
|
|
|
|
# Set model to eval
|
2021-06-20 15:04:51 +02:00
|
|
|
net.eval()
|
2021-06-15 01:36:18 +02:00
|
|
|
|
2021-06-20 15:04:51 +02:00
|
|
|
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
2021-06-15 01:36:18 +02:00
|
|
|
|
2021-06-20 15:04:51 +02:00
|
|
|
folderlist = os.listdir(os.path.dirname(__file__) + "\\test")
|
2021-06-15 01:36:18 +02:00
|
|
|
|
2021-06-20 15:04:51 +02:00
|
|
|
tested = 0
|
|
|
|
correct = 0
|
2021-06-15 01:36:18 +02:00
|
|
|
|
2021-06-20 15:04:51 +02:00
|
|
|
for folder in folderlist:
|
|
|
|
for file in os.listdir(os.path.dirname(__file__) + "\\test\\" + folder):
|
|
|
|
if neural_network.result_from_network(net, os.path.dirname(__file__) + "\\test\\" + folder + "\\" + file) == folder:
|
|
|
|
correct += 1
|
|
|
|
tested += 1
|
|
|
|
else:
|
|
|
|
tested += 1
|
2021-06-15 01:36:18 +02:00
|
|
|
|
2021-06-20 15:04:51 +02:00
|
|
|
print(correct/tested)
|
2021-06-15 01:36:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
NN_accuracy()
|