#own file imports import helper_functions import spectroscopy_cnn_model import load_data import numpy as np normalize = sys.argv[1] output_spectra_length = 300 spectra_file = 'spectra.npz' experiment_model = 'exp42' train_loader, test_loader, validation_loader = load_data.load_experiment_data( spectra_file, 'all', 1, 1, 1) model = spectroscopy_cnn_model.create_network(output_spectra_length) model.load_state_dict( torch.load('results/model_' + experiment_model + '.pth', map_location='cpu')) model.eval() predicted_spectra_training = [] predicted_spectra_testing = [] predicted_spectra_validation = [] with torch.no_grad(): print("Predictions training data") for data, target in train_loader: output = model(data)
coulomb_train, coulomb_test, energies_train, energies_test = train_test_split( coulomb, energies, test_size=1.0 - train_split, random_state=0) coulomb_test, coulomb_val, energies_test, energies_val = train_test_split( coulomb_test, energies_test, test_size=val_test_split, random_state=0) def relative_difference(prediction, label): dE = 30 / len(prediction) #how many eV's one dE is numerator = np.sum(dE * np.power((label - prediction), 2)) denominator = np.sum(dE * label) return 1 - np.sqrt(numerator) / denominator validation_loader = load_data.load_experiment_data('spectra.npz', 'validation') model = spectroscopy_cnn_model.create_network(300) model.load_state_dict(torch.load('results/model_exp17.pth', map_location='cpu')) model.eval() rmse_accuracy = helper_functions.get_model_error(validation_loader, model, True) best_prediction = np.argmin(rmse_accuracy) worst_prediction = np.argmax(rmse_accuracy) median_prediction = rmse_accuracy.index( np.percentile(rmse_accuracy, 50, interpolation='nearest')) index = 1836 index2 = 5670