Пример #1
0
# 处理花费时间较长的情况下减少数据 
#x_train, t_train = x_train[:5000], t_train[:5000]
#x_test, t_test = x_test[:1000], t_test[:1000]

max_epochs = 20

network = SimpleConvNet(input_dim=(1,28,28), 
                        conv_param = {'filter_num': 30, 'filter_size': 5, 'pad': 0, 'stride': 1},
                        hidden_size=100, output_size=10, weight_init_std=0.01)
                        
trainer = Trainer(network, x_train, t_train, x_test, t_test,
                  epochs=max_epochs, mini_batch_size=100,
                  optimizer='Adam', optimizer_param={'lr': 0.001},
                  evaluate_sample_num_per_epoch=1000)
trainer.train()

# 保存参数
network.save_params("params.pkl")
print("Saved Network Parameters!")

# 绘制图形
markers = {'train': 'o', 'test': 's'}
x = np.arange(max_epochs)
plt.plot(x, trainer.train_acc_list, marker='o', label='train', markevery=2)
plt.plot(x, trainer.test_acc_list, marker='s', label='test', markevery=2)
plt.xlabel("epochs")
plt.ylabel("accuracy")
plt.ylim(0, 1.0)
plt.legend(loc='lower right')
plt.show()
Пример #2
0
# 테스트 도우미 클래스
trainer = Trainer(network=cnn,
                  x_train=X_train,
                  t_train=Y_train,
                  x_test=X_test,
                  t_test=Y_test,
                  epochs=20,
                  mini_batch_size=100,
                  optimizer='Adam',
                  optimizer_param={'lr': 0.01},
                  evaluate_sample_num_per_epoch=1000)
# 테스트 실행
trainer.train()

# 학습이 끝난 후 파라미터들을 파일에 저장
cnn.save_params('cnn_params.pkl')

# 그래프(x축 - epoch, y축 - 정확도(accuracy))
x = numpy.arange(20)
plt.plot(x, trainer.train_acc_list, label='train accuracy')
plt.plot(x, trainer.test_acc_list, label='test accuracy')
plt.legend()
plt.xlabel('epoch')
plt.ylabel('accuracy')
plt.show()