def make_network2(input_shape=INPUT_SHAPE): return (NeuralNetwork() .input(input_shape) .conv([5, 5, 12]) # <== doubled .max_pool() .relu() .conv([5, 5, 32]) # <== doubled .max_pool() .relu() .flatten() .dense(240) # <== doubled .relu() .dense(N_CLASSES)) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network2(), make_adam(1.0e-3)) learning_curve = train_evaluate(pipeline) session.save('checkpoint/network2.ckpt') show_learning_curve(learning_curve) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network2()) session.load('checkpoint/network2.ckpt') pred = pipeline.predict(X_valid) cm = confusion_matrix(y_valid, pred) plot_confusion_matrix(cm) print_confusion_matrix(cm) '''X_new = np.array(glob.glob('images/*.ppm')) new_images = [plt.imread(path) for path in X_new]
for result in sorted(results, key=lambda x: -x[2]): print('{:>2} {:<50} {:6.2f}% {:>4}'.format(*result, sum(y_train==result[0]))) accuracies.append(result[2]) print('-'*50) print('Accuracy: Mean: {:.3f} Std: {:.3f}'.format(np.mean(accuracies), np.std(accuracies))) def make_network3(input_shape=INPUT_SHAPE): return (NeuralNetwork() .input(input_shape) .conv([5, 5, 24]) # <== doubled .max_pool() .relu() .conv([5, 5, 64]) # <== doubled .max_pool() .relu() .flatten() .dense(480) # <== doubled .relu() .dense(N_CLASSES)) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network3(), make_adam(0.5e-3)) learning_curve = train_evaluate(pipeline,epochs=100) session.save('checkpoint/network3_e_100_lr_0.5e-3.ckpt') show_learning_curve(learning_curve) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network3()) session.load('checkpoint/network3_e_100_lr_0.5e-3.ckpt') pred = pipeline.predict(X_valid) cm = confusion_matrix(y_valid, pred) plot_confusion_matrix(cm) print_confusion_matrix(cm)
sum(y_train == result[0]))) accuracies.append(result[2]) print('-' * 50) print('Accuracy: Mean: {:.3f} Std: {:.3f}'.format(np.mean(accuracies), np.std(accuracies))) def make_network5(input_shape=INPUT_SHAPE): return (NeuralNetwork().input(input_shape).conv( [5, 5, 24]).max_pool().elu() # <== ELU .conv([5, 5, 64]).max_pool().elu() # <== ELU .flatten().dense(480).elu() # <== ELU .dense(N_CLASSES)) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network5(), make_adam(0.5e-3)) learning_curve = train_evaluate(pipeline, epochs=20) session.save('checkpoint/network5.ckpt') show_learning_curve(learning_curve) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network5()) session.load('checkpoint/network5.ckpt') pred = pipeline.predict(X_valid) cm = confusion_matrix(y_valid, pred) plot_confusion_matrix(cm) print_confusion_matrix(cm)
accuracies = [] for result in sorted(results, key=lambda x: -x[2]): print('{:>2} {:<50} {:6.2f}% {:>4}'.format(*result, sum(y_train == result[0]))) accuracies.append(result[2]) print('-' * 50) print('Accuracy: Mean: {:.3f} Std: {:.3f}'.format(np.mean(accuracies), np.std(accuracies))) def make_network3(input_shape=INPUT_SHAPE): return (NeuralNetwork().input(input_shape).conv([5, 5, 24]) # <== doubled .max_pool().relu().conv([5, 5, 64]) # <== doubled .max_pool().relu().flatten().dense(480) # <== doubled .relu().dense(N_CLASSES)) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network3(), make_adam(1.0e-3)) learning_curve = train_evaluate(pipeline, epochs=20) session.save('checkpoint/network3_epochs20.ckpt') show_learning_curve(learning_curve) with Session() as session: pipeline = build_pipeline(preprocessors, session, make_network3()) session.load('checkpoint/network3_epochs100.ckpt') pred = pipeline.predict(X_valid) cm = confusion_matrix(y_valid, pred) plot_confusion_matrix(cm) print_confusion_matrix(cm)