Torch_EEG_plants_electrophy.../test.py
2026-05-13 11:39:59 +02:00

25 lines
855 B
Python

from traindata import *
from model import *
# Function to test the model
def test():
# Load the model that we saved at the end of the training loop
model001 = EEGNet()
data_dir = "C:/DATA/M1/Stages/Fablab/dataclean"
# path = "NetModel.pth"
model001.load_state_dict(torch.load(data_dir))
running_accuracy = 0
total = 0
with torch.no_grad():
for data in test_loader:
inputs, outputs = data
outputs = outputs.to(torch.float32)
predicted_outputs = model(inputs)
_, predicted = torch.max(predicted_outputs, 1)
total += outputs.size(0)
running_accuracy += (predicted == outputs).sum().item()
print('Accuracy of the model based on the test set of', test_split ,'inputs is: %d %%' % (100 * running_accuracy / total))