def save_single_video(self): my_multi_test_datasets = multi_test_datasets( batch_size=self.batch_size, video_num=self.video_imgs_num, frame_interval=2, is_frame=True, is_Optical=False, crop_size=4, img_size=self.img_size_h) gpu_options = tf.GPUOptions(allow_growth=True) with tf.Session(config=tf.ConfigProto( gpu_options=gpu_options)) as sess: sess.run(tf.global_variables_initializer()) self.restore_model_weghts(sess) seletced_dataset_idx = 3 selected_video_idx = 2 video_label = my_multi_test_datasets.init_test_single_videos( seletced_dataset_idx, selected_video_idx) video_lenth = 0 image_batches_list = [] while 1: batches = my_multi_test_datasets.get_single_videos_batches() if not (batches == []): # print(batches.shape) video_lenth += (batches.shape[0] * batches.shape[1]) out_image1, out_image2 = sess.run( [self.out_image_con1, self.out_image_con2], feed_dict={ self.train_in_ph: batches, self.phase: False }) image_batches_list.append(out_image1) image_batches_list.append(out_image2) else: break image_batches_list = np.concatenate(image_batches_list, axis=0) save_batch_images( image_batches_list, self.gray_img_save_path, 'datasets_%d_video_%d.jpg' % (seletced_dataset_idx, selected_video_idx)) print('test') return
def test_single_dataset_type2(self): my_multi_test_datasets = multi_test_datasets( batch_size=self.batch_size, video_num=self.video_imgs_num, frame_interval=2, is_frame=True, is_Optical=True, crop_size=4, img_size=self.img_size_h) gpu_options = tf.GPUOptions(allow_growth=True) with tf.Session(config=tf.ConfigProto( gpu_options=gpu_options)) as sess: sess.run(tf.global_variables_initializer()) self.restore_model_weghts(sess) seletced_dataset_idx = 3 datasets_op_list = [] datasets_gr_list = [] datasets_to_list = [] datasets_tr_list = [] datasets_la_list = [] for video_idx in range( my_multi_test_datasets. multi_datasets[seletced_dataset_idx].video_clips_num): video_label = my_multi_test_datasets.init_test_single_videos( seletced_dataset_idx, video_idx) video_lenth = 0 optical_loss_list = [] gray_loss_list = [] trible_loss_list = [] while 1: batches = my_multi_test_datasets.get_single_videos_batches( ) if not (batches == []): # print(batches.shape) video_lenth += (batches.shape[0] * batches.shape[1]) optical_loss, gray_loss, mid_stage_loss = sess.run( [ self.optical_loss_sequences_frame_mean, self.gray_loss_sequences_frame_mean, self.midstage_loss_sequences_frame_mean ], feed_dict={ self.train_in_ph: batches, self.phase: False }) print('optical loss shape', optical_loss.shape) print('gray loss shape', gray_loss.shape) print('mid stage loss', mid_stage_loss.shape) trib_loss = np.ones_like(optical_loss, dtype=np.float) for b_idx in range(optical_loss.shape[0]): trib_loss[b_idx, :] = 0 * optical_loss[ b_idx, :] + 0 * gray_loss[ b_idx, :] + mid_stage_loss[b_idx] print(optical_loss[b_idx, :]) print(gray_loss[b_idx, :]) print(mid_stage_loss[b_idx]) print(trib_loss[b_idx, :]) optical_loss = optical_loss.flatten() gray_loss = gray_loss.flatten() trib_loss = trib_loss.flatten() optical_loss_list.append(optical_loss) gray_loss_list.append(gray_loss) trible_loss_list.append(trib_loss) else: print('optical-loss') tog_loss = max_min_np( np.concatenate(optical_loss_list, axis=0) + np.concatenate(gray_loss_list, axis=0)) datasets_to_list.append(tog_loss) optical_loss_list = max_min_np( np.concatenate(optical_loss_list, axis=0)) datasets_op_list.append(optical_loss_list) gray_loss_list = max_min_np( np.concatenate(gray_loss_list, axis=0)) datasets_gr_list.append(gray_loss_list) trible_loss_list = max_min_np( np.concatenate(trible_loss_list, axis=0)) print('trible - loss - normalized', trible_loss_list) datasets_tr_list.append(trible_loss_list) datasets_la_list.append(video_label) break datasets_op_list = np.concatenate(datasets_op_list, axis=0) datasets_gr_list = np.concatenate(datasets_gr_list, axis=0) datasets_to_list = np.concatenate(datasets_to_list, axis=0) datasets_tr_list = np.concatenate(datasets_tr_list, axis=0) datasets_la_list = np.concatenate(datasets_la_list, axis=0) print('optical-loss') frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_op_list, datasets_la_list) print('gray-loss') frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_gr_list, datasets_la_list) print('together-loss') frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_to_list, datasets_la_list) print('trible-loss') # print(datasets_tr_list) print('label') # print(datasets_la_list) frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_tr_list, datasets_la_list) frame_auc, frame_eer = save_roc_auc_plot_img( '', 1 - datasets_tr_list, datasets_la_list) print('test') return
def test_video(self): def reshape_batches(inputs_batches): return np.reshape( inputs_batches, newshape=[ inputs_batches.shape[0] * inputs_batches.shape[1], inputs_batches.shape[2], inputs_batches.shape[3], inputs_batches.shape[4] ]) my_multi_test_datasets = multi_test_datasets(batch_size=4, video_num=4, frame_interval=2, is_frame=True, is_Optical=False, crop_size=4, img_size=self.img_size_h) gpu_options = tf.GPUOptions(allow_growth=True) with tf.Session(config=tf.ConfigProto( gpu_options=gpu_options)) as sess: sess.run(tf.global_variables_initializer()) self.restore_model_weghts(sess) video_label = my_multi_test_datasets.init_test_single_videos( seletced_dataset_idx=2, selected_video_idx=2) video_lenth = 0 psnr1_list = [] optical_loss_list = [] gray_loss_list = [] optical_frame_list = [] gray_frame_list = [] optical_frame_label_list = [] gray_frame_label_list = [] while 1: batches = my_multi_test_datasets.get_single_videos_batches() if not (batches == []): print(batches.shape) video_lenth += (batches.shape[0] * batches.shape[1]) batch_data_gray = batches[:, :, :, :, 0:1] try: gray_loss, gray_frames, gray_psnr1 = sess.run( [ self.gray_loss_sequences_frame_mean, self.gray_train_out_ph, self.gray_loss_sequences_frame_psnr1 ], feed_dict={ self.gray_train_in_ph: batch_data_gray, self.phase: False }) print('gray loss shape', gray_loss.shape) print('psnr shape', gray_psnr1.shape) # print('gray loss shape',gray_loss.shape) gray_loss = gray_loss.flatten() gray_psnr1 = gray_psnr1.flatten() gray_frame_list.append(reshape_batches(gray_frames)) gray_frame_label_list.append( reshape_batches(batch_data_gray)) gray_loss_list.append(gray_loss) psnr1_list.append(gray_psnr1) except Exception: print('get img failed') else: break # print('optical-loss') # optical_loss_list = max_min_np(np.concatenate(optical_loss_list,axis=0)) # save_roc_auc_plot_img('',optical_loss_list, video_label) print('gray-loss') gray_loss_list = max_min_np(np.concatenate(gray_loss_list, axis=0)) print(gray_loss_list) print(video_label) save_roc_auc_plot_img('', gray_loss_list, video_label) print('psnr1-auc') gray_psnr1 = max_min_np(np.concatenate(psnr1_list, axis=0)) print(gray_psnr1) save_roc_auc_plot_img('', gray_psnr1, video_label) gray_frame_list = np.concatenate(gray_frame_list, axis=0) # optical_frame_list = np.concatenate(optical_frame_list, axis=0) gray_frame_label_list = np.concatenate(gray_frame_label_list, axis=0) # optical_frame_label_list = np.concatenate(optical_frame_label_list, axis=0) gray_frame_list = np.concatenate( [gray_frame_list, gray_frame_label_list], axis=1) # optical_frame_list = np.concatenate([optical_frame_list, optical_frame_label_list], axis=2) save_batch_images(gray_frame_list, self.gray_img_save_path, 'test_gray.jpg') return
def test_single_dataset_type2(self): my_multi_test_datasets = multi_test_datasets( batch_size=self.batch_size, video_num=self.video_imgs_num, frame_interval=2, is_frame=True, is_Optical=True, crop_size=4, img_size=self.img_size_h) gpu_options = tf.GPUOptions(allow_growth=True) with tf.Session(config=tf.ConfigProto( gpu_options=gpu_options)) as sess: sess.run(tf.global_variables_initializer()) self.restore_model_weghts(sess) seletced_dataset_idx = 0 datasets_op_list = [] datasets_gr_list = [] datasets_to_list = [] datasets_tr_list = [] datasets_la_list = [] datasest_psnr_list = [] for video_idx in range( my_multi_test_datasets. multi_datasets[seletced_dataset_idx].video_clips_num): video_label = my_multi_test_datasets.init_test_single_videos( seletced_dataset_idx, video_idx) video_lenth = 0 optical_loss_list = [] gray_loss_list = [] trible_loss_list = [] psnr_list = [] while 1: batches = my_multi_test_datasets.get_single_videos_batches( ) if not (batches == []): # print(batches.shape) video_lenth += (batches.shape[0] * batches.shape[1]) test_loss = self.fetch_net_test_loss(sess, batches) optical_loss_list.append( test_loss['optical_loss_sequence']) gray_loss_list.append(test_loss['gray_loss_sequence']) trible_loss_list.append(test_loss['mid_loss_sequence']) psnr_list.append(test_loss['psnr_sequence']) else: print('together-loss') tog_loss = max_min_np( np.concatenate(optical_loss_list, axis=0) + np.concatenate(gray_loss_list, axis=0)) datasets_to_list.append(tog_loss) print('optical-loss') optical_loss_list = max_min_np( np.concatenate(optical_loss_list, axis=0)) datasets_op_list.append(optical_loss_list) print('gray-loss') gray_loss_list = max_min_np( np.concatenate(gray_loss_list, axis=0)) datasets_gr_list.append(gray_loss_list) print('trible-loss') trible_loss_list = max_min_np( np.concatenate(trible_loss_list, axis=0)) print('trible - loss - normalized', trible_loss_list) datasets_tr_list.append(trible_loss_list) print('psnr list') psnr_list = max_min_np( np.concatenate(psnr_list, axis=0)) print(psnr_list.shape) datasest_psnr_list.append(psnr_list) datasets_la_list.append(video_label) break datasets_op_list = np.concatenate(datasets_op_list, axis=0) datasets_gr_list = np.concatenate(datasets_gr_list, axis=0) datasets_to_list = np.concatenate(datasets_to_list, axis=0) datasets_tr_list = np.concatenate(datasets_tr_list, axis=0) datasets_la_list = np.concatenate(datasets_la_list, axis=0) datasest_psnr_list = np.concatenate(datasest_psnr_list, axis=0) print('optical-loss') frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_op_list, datasets_la_list) print('gray-loss') frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_gr_list, datasets_la_list) print('together-loss') frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_to_list, datasets_la_list) print('trible-loss') # print(datasets_tr_list) frame_auc, frame_eer = save_roc_auc_plot_img( '', datasets_tr_list, datasets_la_list) frame_auc, frame_eer = save_roc_auc_plot_img( '', 1 - datasets_tr_list, datasets_la_list) print('psnr-loss') frame_auc, frame_eer = save_roc_auc_plot_img( '', datasest_psnr_list, datasets_la_list) print('test') return