# for img0 in image.cpu().numpy(): # cv2.imshow('image', img0) # cv2.waitKey(100) # print(label.cpu().numpy()) total += float(labels2.size(0)) correct += float(predicted.eq(labels2).sum().item()) if batch_idx % 100 == 0: acc = 100. * float(correct) / float(total) print(batch_idx, len(test_loader), ' Acc: %.5f' % acc) class_names = ['0 ', '1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 '] # ['0_zoom_out', '1_zoom_out', '2_zoom_out', '3_zoom_out', '4_zoom_out', # '5_zoom_out', '6_zoom_out', '7_zoom_out', '8_zoom_out', '9_zoom_out', # '0_zoom_in', '1_zoom_in', '2_zoom_in', '3_zoom_in', '4_zoom_in', # '5_zoom_in', '6_zoom_in', '7_zoom_in', '8_zoom_in', '9_zoom_in'] plot_confusion_matrix(cm, class_names) print('Iters:', epoch, '\n\n\n') print('Test Accuracy of the model on the 10000 test images: %.3f' % (100 * correct / total)) acc = 100. * float(correct) / float(total) acc_record.append(acc) if epoch % 5 == 0: print(acc) print('Saving..') state = { 'net': snn.state_dict(), 'acc': acc, 'epoch': epoch, 'acc_record': acc_record, } if not os.path.isdir('checkpoint'):
conf_mat_train = confusion_matrix(y_train, pred_train, labels=[0, 1, 2, 3, 4, 5]) classes = [ 'walking', 'walking up', 'walking down', 'sitting', 'standing', 'laying' ] classes = np.array(classes) ### Printing and plotting operation of results ### # Test accuracy print('Test Accuracy: ', accuracy_score(y_test, pred_test)) plt.figure(1) plot_confusion_matrix(conf_mat_test, classes, normalize=True, title='Confusion matrix') fname_test = os.getcwd() + '/Confusion Matrices/LDA_test_all.png' plt.savefig(fname_test, dpi=256, edgecolor='b', format='png', frameon=True) # calculating train accuracy score print('Train Accuracy: ', accuracy_score(y_train, pred_train)) plt.figure(2) plot_confusion_matrix(conf_mat_train, classes, normalize=True, title='Confusion matrix') fname = os.getcwd() + '/Confusion Matrices/LDA_train_all.png' plt.savefig(fname, dpi=256, edgecolor='b', format='png', frameon=True) plt.show()