Пример #1
0
    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
Пример #2
0
    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]

                    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('optical loss shape',optical_loss.shape)
                    print('gray loss shape', gray_loss.shape)

                    print('psnr shape', gray_psnr1.shape)
                    # print('gray loss shape',gray_loss.shape)

                    # optical_loss = optical_loss.flatten()
                    gray_loss = gray_loss.flatten()

                    gray_psnr1 = gray_psnr1.flatten()

                    # optical_frame_list.append(reshape_batches(optical_frames))
                    gray_frame_list.append(reshape_batches(gray_frames))

                    gray_frame_label_list.append(
                        reshape_batches(batch_data_gray))
                    # optical_frame_label_list.append(reshape_batches(batch_data_optical))

                    # optical_loss_list.append(optical_loss)
                    gray_loss_list.append(gray_loss)
                    psnr1_list.append(gray_psnr1)

                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