draw_filters(xparray(model.conv21.W), '%s/log_conv21_epoch_%d.jpg' % (result_dir, epoch)) draw_filters_sq(xparray(model.conv12.W), '%s/log_conv12_epoch_%d.jpg' % (result_dir, epoch), 16) draw_filters_sq(xparray(model.conv22.W), '%s/log_conv22_epoch_%d.jpg' % (result_dir, epoch), 16) # 適当なファイルの画像を入力する video_num = int(np.random.random() * len(test_vis)) s_image_vis = xp.asarray(test_vis[video_num]).astype(np.float32) s_image_dep = xp.asarray(test_dep[video_num]).astype(np.float32) # プーリング1層まで通した結果を出力 frame_num = int(s_image_vis.shape[0]/ 2) draw_image(xparray(model.extract_pool11(s_image_vis[frame_num,:,:]).data), '%s/sample_vis_pool1_%d.jpg' % (result_dir, epoch)) draw_image(xparray(model.extract_pool21(s_image_dep[frame_num,:,:]).data), '%s/sample_dep_pool1_%d.jpg' % (result_dir, epoch)) # 学習曲線を出力 draw_loss_curve(log_fn, '%s/log.jpg' % result_dir) print("Confusion Matrix for train data:") print_confmat(conf_array_train) print("Confusion Matrix for test data:") print_confmat(conf_array_test) np.savetxt('%s/confmat_train_epoch_%d.csv' % (result_dir, epoch), conf_array_train, delimiter=',', fmt='%d') np.savetxt('%s/confmat_test_epoch_%d.csv' % (result_dir, epoch), conf_array_test, delimiter=',', fmt='%d') # テストセットの予測を出力 f = open('%s/pred_test_epoch_%d.csv' % (result_dir, epoch), 'w') writer = csv.writer(f) for i in range(len(pred)): writer.writerow(test_labels_epoch[i].tolist())
model_fn = '%s/%s_epoch_%d.chainermodel' % ( result_dir, args.model, epoch) pickle.dump(model, open(model_fn, 'wb'), -1) """ CNNで各層を可視化 1,2層の可視化 """ if epoch % args.visualize == 0: draw_filters(xparray(model.conv11.W), '%s/log_conv11_epoch_%d.jpg' % (result_dir, epoch)) draw_filters(xparray(model.conv21.W), '%s/log_conv21_epoch_%d.jpg' % (result_dir, epoch)) draw_filters_sq(xparray(model.conv12.W), '%s/log_conv12_epoch_%d.jpg' % (result_dir, epoch), 16) draw_filters_sq(xparray(model.conv22.W), '%s/log_conv22_epoch_%d.jpg' % (result_dir, epoch), 16) # 学習曲線を出力 draw_loss_curve(log_fn, '%s/loss_accuracy.jpg' % result_dir, result_dir, args.epoch_offset) labels = "sf123456789012345678901234567890123456789012345678901234567890"[0:num_labels] # 混同行列を表示 print("Confusion Matrix for train data:") print_confmat(conf_array_train) print("Confusion Matrix for test data:") print_confmat(conf_array_test) # 混同行列をcsvに出力 np.savetxt('%s/confmat_train_epoch_%d.csv' % (result_dir, epoch), conf_array_train, delimiter=',', fmt='%d') np.savetxt('%s/confmat_test_epoch_%d.csv' % (result_dir, epoch), conf_array_test, delimiter=',', fmt='%d') # テストセットの予測を出力
1,2層の可視化 """ if epoch % args.visualize == 0: draw_filters(xparray(model.conv11.W), '%s/log_conv11_epoch_%d.jpg' % (result_dir, epoch)) draw_filters(xparray(model.conv21.W), '%s/log_conv21_epoch_%d.jpg' % (result_dir, epoch)) draw_filters_sq(xparray(model.conv12.W), '%s/log_conv12_epoch_%d.jpg' % (result_dir, epoch), 16) draw_filters_sq(xparray(model.conv22.W), '%s/log_conv22_epoch_%d.jpg' % (result_dir, epoch), 16) # 学習曲線を出力 draw_loss_curve(log_fn, '%s/loss_accuracy.jpg' % result_dir, result_dir, args.epoch_offset) labels = "sf123456789012345678901234567890123456789012345678901234567890"[ 0:num_labels] # 混同行列を表示 print("Confusion Matrix for train data:") print_confmat(conf_array_train) print("Confusion Matrix for test data:") print_confmat(conf_array_test) # 混同行列をcsvに出力 np.savetxt('%s/confmat_train_epoch_%d.csv' % (result_dir, epoch), conf_array_train, delimiter=',',