x_batch = xp.asarray(x_test[i: i + batch_size]) y_batch = xp.asarray(y_test[i: i + batch_size]) acc = forward(x_batch, y_batch, train=False) sum_acc += float(acc.data) * len(y_batch) epoch_acc = sum_acc / N_test log.info("test accuracy: {0}".format(epoch_acc)) fp_acc.write("{0}\t{1}\n".format(epoch, epoch_acc)) fp_acc.flush() # モデルパラメータの途中保存 if check_interval > 0 and (epoch % check_interval) == 0: check_file = "result/{0:0>3}_".format(epoch) + args.model log.info("Checkpoint : {0}".format(check_file)) param = model.to_cpu().parameters np.save(check_file, param) end_time = time.clock() log.info("Trainging time: {0} [s]".format(end_time - start_time)) fp_acc.close() fp_loss.close() # モデルのパラメータを保存 if n_epoch > 0: log.info("Save model parameters : {0}".format(param_file)) param = model.to_cpu().parameters np.save(param_file, param) if plot_model == 1: # 重みを表示 plot_mlp_weight(model, "l1", shape=(28, 28)) plot_mlp_weight(model, "l2", shape=(16, 16))