Пример #1
0
    def test_transform_set_select_curate_min_size_fails_due_to_missing_required_option(
            self):  # noqa
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(
                __file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            DefaultVideoSelectExtractPlugin().video_select_extract(1)  # noqa

            self.mock_transform_set()

            with self.assertRaises(ValueError):
                try:
                    MinSizeTransformSetSelectCuratePlugin(
                    ).transform_set_select_curate(1, {})  # noqa
                except ValueError as e:
                    self.assertEqual(
                        str(e),
                        'The min-size option is required but was not supplied'
                    )  # noqa

                    raise e
    def test_transform_set_select_extract_max_size(self):
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(
                __file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            DefaultVideoSelectExtractPlugin().video_select_extract(1)  # noqa

            self.mock_transform_set()

            with mock.patch.dict(os.environ, {'MODEL_LIST_LENGTH': '2'}):
                transform_set_id = MaxSizeTransformSetSelectExtractPlugin(
                ).transform_set_select_extract(1, {})  # noqa

            self.assertEqual(transform_set_id, 2)

            # db
            result = TransformSetModel().select(2)
            self.assertEqual(result, (2, 'max_size', 1, 1))

            result = TransformModel().list(2)
            self.assertEqual(len(result), 5)
            t = list(result[0])
            json.loads(t.pop(3))
            self.assertEqual(t, [6, 2, 1, 0])
            t = list(result[1])
            json.loads(t.pop(3))
            self.assertEqual(t, [7, 2, 2, 0])
            t = list(result[2])
            json.loads(t.pop(3))
            self.assertEqual(t, [8, 2, 3, 0])
            t = list(result[3])
            json.loads(t.pop(3))
            self.assertEqual(t, [9, 2, 4, 0])
            t = list(result[4])
            json.loads(t.pop(3))
            self.assertEqual(t, [10, 2, 5, 0])

            # files
            p1 = TransformSetSubDir.path(2)

            # transforms
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 6, 'jpg')).shape[0],
                299)  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 7, 'jpg')).shape[0],
                299)  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 8, 'jpg')).shape[0],
                299)  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 9, 'jpg')).shape[0],
                299)  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 10, 'jpg')).shape[0],
                299)  # noqa
    def test_video_select_extract(self):
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(
                __file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            frame_set_id = DefaultVideoSelectExtractPlugin(
            ).video_select_extract(1)  # noqa
            self.assertEqual(frame_set_id, 1)

            # db
            result = FrameSetModel().select(1)
            self.assertEqual(result, (1, 1))

            result = FrameModel().list(1)
            self.assertEqual(len(result), 5)
            self.assertEqual(result[0], (1, 1, 0))
            self.assertEqual(result[1], (2, 1, 0))
            self.assertEqual(result[2], (3, 1, 0))
            self.assertEqual(result[3], (4, 1, 0))
            self.assertEqual(result[4], (5, 1, 0))

            # files
            p1 = FrameSetSubDir.path(1)

            # frames
            self.assertIsInstance(cv2.imread(FrameFile.path(p1, 1, 'jpg')),
                                  np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(FrameFile.path(p1, 2, 'jpg')),
                                  np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(FrameFile.path(p1, 3, 'jpg')),
                                  np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(FrameFile.path(p1, 4, 'jpg')),
                                  np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(FrameFile.path(p1, 5, 'jpg')),
                                  np.ndarray)  # noqa

            # thumbnails
            self.assertEqual(
                cv2.imread(FrameFile.path(p1, 1, 'jpg', '192x192')).shape[1],
                192)  # noqa
            self.assertEqual(
                cv2.imread(FrameFile.path(p1, 2, 'jpg', '192x192')).shape[1],
                192)  # noqa
            self.assertEqual(
                cv2.imread(FrameFile.path(p1, 3, 'jpg', '192x192')).shape[1],
                192)  # noqa
            self.assertEqual(
                cv2.imread(FrameFile.path(p1, 4, 'jpg', '192x192')).shape[1],
                192)  # noqa
            self.assertEqual(
                cv2.imread(FrameFile.path(p1, 5, 'jpg', '192x192')).shape[1],
                192)  # noqa
Пример #4
0
    def test_transform_set_select_extract_pad_rejected(self):
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(
                __file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            DefaultVideoSelectExtractPlugin().video_select_extract(1)  # noqa

            self.mock_transform_set()

            MaxSizeTransformSetSelectExtractPlugin(
            ).transform_set_select_extract(1, {})  # noqa

            transform_model = TransformModel()
            transform_model.update(7, rejected=1)
            transform_model.update(9, rejected=1)

            with mock.patch.dict(os.environ, {'MODEL_LIST_LENGTH': '2'}):
                transform_set_id = PadTransformSetSelectExtractPlugin(
                ).transform_set_select_extract(2, {})  # noqa

            self.assertEqual(transform_set_id, 3)

            # db
            result = TransformSetModel().select(3)
            self.assertEqual(result, (3, 'pad', 1, 2))

            result = TransformModel().list(3)
            self.assertEqual(len(result), 3)
            t = list(result[0])
            json.loads(t.pop(3))
            self.assertEqual(t, [11, 3, 1, 0])
            t = list(result[1])
            json.loads(t.pop(3))
            self.assertEqual(t, [12, 3, 3, 0])
            t = list(result[2])
            json.loads(t.pop(3))
            self.assertEqual(t, [13, 3, 5, 0])

            # files
            p1 = TransformSetSubDir.path(3)

            # transforms
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 11,
                                                                'jpg')),
                                  np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 12,
                                                                'jpg')),
                                  np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 13,
                                                                'jpg')),
                                  np.ndarray)  # noqa
    def test_frame_set_select_extract_face(self):
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(__file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            DefaultVideoSelectExtractPlugin().video_select_extract(1)  # noqa

            with mock.patch.dict(os.environ, {'MODEL_LIST_LENGTH': '2'}):
                transform_set_id = MTCNNFrameSetSelectExtractPlugin().frame_set_select_extract(1, {})  # noqa

            self.assertEqual(transform_set_id, 1)

            # db
            result = TransformSetModel().select(1)
            self.assertEqual(result, (1, 'face', 1, None))

            result = TransformModel().list(1)
            self.assertEqual(len(result), 5)
            t = list(result[0])
            json.loads(t.pop(3))
            self.assertEqual(t, [1, 1, 1, 0])
            t = list(result[1])
            json.loads(t.pop(3))
            self.assertEqual(t, [2, 1, 2, 0])
            t = list(result[2])
            json.loads(t.pop(3))
            self.assertEqual(t, [3, 1, 3, 0])
            t = list(result[3])
            json.loads(t.pop(3))
            self.assertEqual(t, [4, 1, 4, 0])
            t = list(result[4])
            json.loads(t.pop(3))
            self.assertEqual(t, [5, 1, 5, 0])

            # files
            p1 = TransformSetSubDir.path(1)

            # transforms
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 1, 'jpg')), np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 2, 'jpg')), np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 3, 'jpg')), np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 4, 'jpg')), np.ndarray)  # noqa
            self.assertIsInstance(cv2.imread(TransformFile.path(p1, 5, 'jpg')), np.ndarray)  # noqa
Пример #6
0
    def test_transform_set_select_curate_min_size(self):
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(
                __file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            DefaultVideoSelectExtractPlugin().video_select_extract(1)  # noqa

            self.mock_transform_set()

            MinSizeTransformSetSelectCuratePlugin(
            ).transform_set_select_curate(1, {'min-size': '300'})  # noqa

            # db
            result = TransformSetModel().select(1)
            self.assertEqual(result, (1, 'face', 1, None))

            result = TransformModel().list(1)
            self.assertEqual(len(result), 5)
            t = list(result[0])
            json.loads(t.pop(3))
            self.assertEqual(t, [1, 1, 1, 0])
            t = list(result[1])
            json.loads(t.pop(3))
            self.assertEqual(t, [2, 1, 2, 1])
            t = list(result[2])
            json.loads(t.pop(3))
            self.assertEqual(t, [3, 1, 3, 0])
            t = list(result[3])
            json.loads(t.pop(3))
            self.assertEqual(t, [4, 1, 4, 1])
            t = list(result[4])
            json.loads(t.pop(3))
            self.assertEqual(t, [5, 1, 5, 0])
    def test_video_select_extract_sub_sample(self):
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(
                __file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            DefaultVideoSelectExtractPlugin().video_select_extract(
                1, sub_sample=2)  # noqa

            # db
            result = FrameModel().list(1)
            self.assertEqual(len(result), 3)
            self.assertEqual(result[0], (1, 1, 0))
            self.assertEqual(result[1], (2, 1, 0))
            self.assertEqual(result[2], (3, 1, 0))

            # files
            p1 = FrameSetSubDir.path(1)

            # frames
            self.assertTrue(os.path.isfile(FrameFile.path(p1, 1, 'jpg')))
            self.assertTrue(os.path.isfile(FrameFile.path(p1, 2, 'jpg')))
            self.assertTrue(os.path.isfile(FrameFile.path(p1, 3, 'jpg')))

            # thumbnails
            self.assertTrue(
                os.path.isfile(FrameFile.path(p1, 1, 'jpg',
                                              '192x192')))  # noqa
            self.assertTrue(
                os.path.isfile(FrameFile.path(p1, 2, 'jpg',
                                              '192x192')))  # noqa
            self.assertTrue(
                os.path.isfile(FrameFile.path(p1, 3, 'jpg',
                                              '192x192')))  # noqa
Пример #8
0
    def test_transform_set_select_extract_pad_size(self):
        with deepstar_path():
            video_0001 = os.path.dirname(os.path.realpath(
                __file__)) + '/../../support/video_0001.mp4'  # noqa

            shutil.copyfile(video_0001, VideoFile.path('video_0001.mp4'))

            VideoModel().insert('test', 'video_0001.mp4')

            DefaultVideoSelectExtractPlugin().video_select_extract(1)  # noqa

            self.mock_transform_set()

            MaxSizeTransformSetSelectExtractPlugin(
            ).transform_set_select_extract(1, {'max-size': '200'})  # noqa

            with mock.patch.dict(os.environ, {'MODEL_LIST_LENGTH': '2'}):
                PadTransformSetSelectExtractPlugin(
                ).transform_set_select_extract(2, {'size': '200'})  # noqa

            # db
            result = TransformSetModel().select(3)
            self.assertEqual(result, (3, 'pad', 1, 2))

            result = TransformModel().list(3)
            self.assertEqual(len(result), 5)
            t = list(result[0])
            json.loads(t.pop(3))
            self.assertEqual(t, [11, 3, 1, 0])
            t = list(result[1])
            json.loads(t.pop(3))
            self.assertEqual(t, [12, 3, 2, 0])
            t = list(result[2])
            json.loads(t.pop(3))
            self.assertEqual(t, [13, 3, 3, 0])
            t = list(result[3])
            json.loads(t.pop(3))
            self.assertEqual(t, [14, 3, 4, 0])
            t = list(result[4])
            json.loads(t.pop(3))
            self.assertEqual(t, [15, 3, 5, 0])

            # files
            p1 = TransformSetSubDir.path(3)

            # transforms
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 11, 'jpg')).shape[:2],
                (200, 200))  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 12, 'jpg')).shape[:2],
                (200, 200))  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 13, 'jpg')).shape[:2],
                (200, 200))  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 14, 'jpg')).shape[:2],
                (200, 200))  # noqa
            self.assertEqual(
                cv2.imread(TransformFile.path(p1, 15, 'jpg')).shape[:2],
                (200, 200))  # noqa
    def test_video_select_extract_fails_to_open_video_file(self):
        with deepstar_path():
            with self.assertRaises(CommandLineRouteHandlerError):
                VideoModel().insert('test', 'test')

                DefaultVideoSelectExtractPlugin().video_select_extract(1)