예제 #1
0
 def test_should_return_batches_equivalent_to_number_of_frames(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info)
     batches = list(video_loader.load())
     dummy_frames = list(self.create_dummy_frames())
     self.assertEqual(len(batches), NUM_FRAMES)
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
예제 #2
0
    def test_should_return_the_new_path_after_execution(self, mock_class):
        class_instatnce = mock_class.return_value

        dummy_expr = type('dummy_expr', (),
                          {"evaluate": lambda x=None: [True, False, True]})

        # Build plan tree
        video = VideoMetaInfo("dummy.avi", 10, VideoFormat.AVI)
        class_instatnce.load.return_value = map(
            lambda x: x,
            [FrameBatch([1, 2, 3], None),
             FrameBatch([4, 5, 6], None)])

        storage_plan = StoragePlan(video)
        seq_scan = SeqScanPlan(predicate=dummy_expr)
        seq_scan.append_child(storage_plan)

        # Execute the plan
        executor = PlanExecutor(seq_scan)
        actual = executor.execute_plan()
        expected = [FrameBatch([1, 3], None), FrameBatch([4, 6], None)]

        mock_class.assert_called_once()

        self.assertEqual(expected, actual)
예제 #3
0
 def convert(statement_list):
     if len(statement_list) > 1 or len(statement_list) == 0:
         print('statement list must be length 1 and it was len: {}'.format(len(statement_list)))
     else:
         statement = statement_list[0]
         # Need to Create the table and projection
         from_stuff = statement.from_table
         meta1 = VideoMetaInfo(file=from_stuff.table_info.table_name, c_format=VideoFormat.MOV, fps=30)
         video1 = SimpleVideoLoader(video_metadata=meta1)
         t1 = TableRef(video=video1, table_info=TableInfo(table_name=from_stuff.table_info.table_name))
         # Creating projection (root)
         projection_output = [target.col_name for target in statement.target_list]
         root = LogicalProjectionPlan(videos=[video1], column_ids=projection_output, foreign_column_ids=[])
         where_stuff = statement.where_clause
         print(where_stuff)
         # Need to create the sigma plan
         if where_stuff is not None:
             # Creating a select Node
             select_node = SeqScanPlan(predicate=where_stuff, column_ids=projection_output, videos=[video1], foreign_column_ids=[])
             root.set_children(select_node)
             select_node.parent=root
             select_node.set_children([t1])
             t1.parent=select_node
         else:
             root.set_children([t1])
             t1.parent = root
         return root
예제 #4
0
 def test_should_return_single_batch_if_batch_size_equal_to_no_of_frames(
         self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info, batch_size=NUM_FRAMES)
     dummy_frames = list(
         self.create_dummy_frames(filters=[i for i in range(NUM_FRAMES)]))
     batches = list(video_loader.load())
     self.assertEqual(1, len(batches))
     self.assertEqual(dummy_frames, list(batches[0].frames))
예제 #5
0
 def test_should_return_only_few_frames_when_limit_is_specified(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     limit = 4
     video_loader = SimpleVideoLoader(video_info, limit=limit)
     dummy_frames = list(
         self.create_dummy_frames(filters=[i for i in range(limit)]))
     batches = list(video_loader.load())
     self.assertEqual(limit, len(batches))
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
예제 #6
0
 def test_should_skip_first_two_frames_with_offset_two(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info, offset=2)
     dummy_frames = list(
         self.create_dummy_frames(filters=[i
                                           for i in range(2, NUM_FRAMES)]))
     batches = list(video_loader.load())
     self.assertEqual(NUM_FRAMES - 2, len(batches))
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
예제 #7
0
 def test_should_return_half_then_number_of_batches_with_skip_of_two(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info, skip_frames=2)
     batches = list(video_loader.load())
     dummy_frames = list(
         self.create_dummy_frames(
             filters=[i * 2 for i in range(NUM_FRAMES // 2)]))
     self.assertEqual(len(batches), NUM_FRAMES / 2)
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
예제 #8
0
    def test_calling_storage_executor_should_return_batches(self, mock_class):
        class_instance = mock_class.return_value

        video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
        storage_plan = StoragePlan(video_info)

        executor = DiskStorageExecutor(storage_plan)

        class_instance.load.return_value = range(5)
        actual = list(executor.next())

        mock_class.assert_called_once_with(video_info,
                                           batch_size=storage_plan.batch_size,
                                           limit=storage_plan.limit,
                                           offset=storage_plan.offset,
                                           skip_frames=storage_plan.skip_frames
                                           )
        class_instance.load.assert_called_once()
        self.assertEqual(list(range(5)), actual)
예제 #9
0
    def findDataNames(self, searchDir):
        """
        findDataNames enumerates all training data for the model and 
        returns a list of tuples where the first element is a EVA VideoMetaInfo 
        object and the second is a string label of 
        the correct video classification

        Inputs:
         - searchDir = path to the directory containing the video data

        Outputs:
         - videoFileNameList = list of tuples where each tuple corresponds 
                               to a video in the data set. 
                               The tuple contains the path to the video,
                               its label, and a nest tuple containing the shape
         - labelList = a list of labels that correspond to labels in labelMap
         - inverseLabelMap = an inverse mapping between the string 
                             representation of the label name and an 
                             integer representation of that label
        """

        # Find all video files and corresponding labels in search directory
        videoFileNameList = glob(searchDir + "**/*.avi", recursive=True)
        random.shuffle(videoFileNameList)

        labels = [split(dirname(a))[1] for a in videoFileNameList]

        videoMetaList = [
            VideoMetaInfo(f, 30, VideoFormat.AVI) for f in videoFileNameList
        ]

        inverseLabelMap = {k: v for (k, v) in enumerate(list(set(labels)))}

        labelMap = {v: k for (k, v) in enumerate(list(set(labels)))}
        labelList = [labelMap[l] for l in labels]

        return (videoMetaList, labelList, inverseLabelMap)