Пример #1
0
        def _run_on_asset(self, asset):
            speed_fassembler = self._get_feature_assembler_instance(asset)
            speed_fassembler.run()
            feature_result = speed_fassembler.results[0]
            result_dict = {}
            result_dict.update(feature_result.result_dict.copy())  # add feature result

            result_dict[self.get_scores_key()] = feature_result.result_dict[
                SpEEDMatlabFeatureExtractor.get_scores_key('speed_4')]  # add SpEED score at scale 4

            return Result(asset, self.executor_id, result_dict)
    def test_run_strred_fextractor(self):
        print 'test on running STRRED feature extractor...'
        ref_path = VmafConfig.test_resource_path("yuv",
                                                 "src01_hrc00_576x324.yuv")
        dis_path = VmafConfig.test_resource_path("yuv",
                                                 "src01_hrc01_576x324.yuv")
        asset = Asset(dataset="test",
                      content_id=0,
                      asset_id=0,
                      workdir_root=VmafConfig.workdir_path(),
                      ref_path=ref_path,
                      dis_path=dis_path,
                      asset_dict={
                          'width': 576,
                          'height': 324
                      })

        asset_original = Asset(dataset="test",
                               content_id=0,
                               asset_id=1,
                               workdir_root=VmafConfig.workdir_path(),
                               ref_path=ref_path,
                               dis_path=ref_path,
                               asset_dict={
                                   'width': 576,
                                   'height': 324
                               })

        self.fextractor = StrredFeatureExtractor([asset, asset_original],
                                                 None,
                                                 fifo_mode=True,
                                                 result_store=None)
        self.fextractor.run(parallelize=True)

        results = self.fextractor.results

        self.assertAlmostEqual(results[0]['STRRED_feature_srred_score'],
                               3.0114681041666671,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_trred_score'],
                               7.3039486249999994,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_strred_score'],
                               21.995608318659482,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_srred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_trred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_strred_score'],
                               0.0,
                               places=4)
    def test_run_SpEED_matlab_fextractor(self):

        print 'test on running SpEED (Matlab) feature extractor...'
        ref_path, dis_path, asset, asset_original = set_default_576_324_videos_for_testing(
        )

        self.fextractor = SpEEDMatlabFeatureExtractor([asset, asset_original],
                                                      None,
                                                      fifo_mode=True,
                                                      result_store=None)

        self.fextractor.run(parallelize=True)
        results = self.fextractor.results
        # S-SpEED assertions on first frame
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_sspeed_2_scores'][0],
                               13.510418,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_sspeed_3_scores'][0],
                               7.211881,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_sspeed_4_scores'][0],
                               4.921501,
                               places=4)
        # T-SpEED assertions on third frame
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_tspeed_2_scores'][2],
                               32.994605,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_tspeed_3_scores'][2],
                               22.404285,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_tspeed_4_scores'][2],
                               15.233468,
                               places=4)
    def test_run_strred_fextractor_blackframes(self):
        print 'test on running STRRED feature extractor on flat frames...'
        ref_path = VmafConfig.test_resource_path("yuv", "flat_1920_1080_0.yuv")
        dis_path = VmafConfig.test_resource_path("yuv",
                                                 "flat_1920_1080_10.yuv")
        asset = Asset(dataset="test",
                      content_id=0,
                      asset_id=0,
                      workdir_root=VmafConfig.workdir_path(),
                      ref_path=ref_path,
                      dis_path=dis_path,
                      asset_dict={
                          'width': 576,
                          'height': 324
                      })

        asset_original = Asset(dataset="test",
                               content_id=0,
                               asset_id=1,
                               workdir_root=VmafConfig.workdir_path(),
                               ref_path=ref_path,
                               dis_path=ref_path,
                               asset_dict={
                                   'width': 576,
                                   'height': 324
                               })

        from vmaf.core.result_store import FileSystemResultStore
        result_store = FileSystemResultStore(logger=None)

        self.fextractor = StrredFeatureExtractor([asset, asset_original],
                                                 None,
                                                 fifo_mode=True,
                                                 result_store=result_store)

        print '    running for the first time with fresh calculation...'
        self.fextractor.run(parallelize=True)

        result0, result1 = self.fextractor.results
        import os
        self.assertTrue(
            os.path.exists(result_store._get_result_file_path(result0)))
        self.assertTrue(
            os.path.exists(result_store._get_result_file_path(result1)))

        print '    running for the second time with stored results...'
        self.fextractor.run(parallelize=True)
        results = self.fextractor.results

        # ignore NaN
        for result in results:
            result.set_score_aggregate_method(ListStats.nonemean)

        self.assertAlmostEqual(results[0]['STRRED_feature_srred_score'],
                               1220.5679849999999,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_trred_score'],
                               50983.3097155,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_strred_score'],
                               62228595.6081,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_srred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_trred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_strred_score'],
                               0.0,
                               places=4)
class ParallelMatlabFeatureExtractorTestNew(unittest.TestCase):
    def tearDown(self):
        if hasattr(self, 'fextractor'):
            self.fextractor.remove_results()
        pass

    def test_run_strred_fextractor(self):
        print 'test on running STRRED feature extractor...'
        ref_path = VmafConfig.test_resource_path("yuv",
                                                 "src01_hrc00_576x324.yuv")
        dis_path = VmafConfig.test_resource_path("yuv",
                                                 "src01_hrc01_576x324.yuv")
        asset = Asset(dataset="test",
                      content_id=0,
                      asset_id=0,
                      workdir_root=VmafConfig.workdir_path(),
                      ref_path=ref_path,
                      dis_path=dis_path,
                      asset_dict={
                          'width': 576,
                          'height': 324
                      })

        asset_original = Asset(dataset="test",
                               content_id=0,
                               asset_id=1,
                               workdir_root=VmafConfig.workdir_path(),
                               ref_path=ref_path,
                               dis_path=ref_path,
                               asset_dict={
                                   'width': 576,
                                   'height': 324
                               })

        self.fextractor = StrredFeatureExtractor([asset, asset_original],
                                                 None,
                                                 fifo_mode=True,
                                                 result_store=None)
        self.fextractor.run(parallelize=True)

        results = self.fextractor.results

        self.assertAlmostEqual(results[0]['STRRED_feature_srred_score'],
                               3.0114681041666671,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_trred_score'],
                               7.3039486249999994,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_strred_score'],
                               21.995608318659482,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_srred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_trred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_strred_score'],
                               0.0,
                               places=4)

    def test_run_strred_fextractor_blackframes(self):
        print 'test on running STRRED feature extractor on flat frames...'
        ref_path = VmafConfig.test_resource_path("yuv", "flat_1920_1080_0.yuv")
        dis_path = VmafConfig.test_resource_path("yuv",
                                                 "flat_1920_1080_10.yuv")
        asset = Asset(dataset="test",
                      content_id=0,
                      asset_id=0,
                      workdir_root=VmafConfig.workdir_path(),
                      ref_path=ref_path,
                      dis_path=dis_path,
                      asset_dict={
                          'width': 576,
                          'height': 324
                      })

        asset_original = Asset(dataset="test",
                               content_id=0,
                               asset_id=1,
                               workdir_root=VmafConfig.workdir_path(),
                               ref_path=ref_path,
                               dis_path=ref_path,
                               asset_dict={
                                   'width': 576,
                                   'height': 324
                               })

        from vmaf.core.result_store import FileSystemResultStore
        result_store = FileSystemResultStore(logger=None)

        self.fextractor = StrredFeatureExtractor([asset, asset_original],
                                                 None,
                                                 fifo_mode=True,
                                                 result_store=result_store)

        print '    running for the first time with fresh calculation...'
        self.fextractor.run(parallelize=True)

        result0, result1 = self.fextractor.results
        import os
        self.assertTrue(
            os.path.exists(result_store._get_result_file_path(result0)))
        self.assertTrue(
            os.path.exists(result_store._get_result_file_path(result1)))

        print '    running for the second time with stored results...'
        self.fextractor.run(parallelize=True)
        results = self.fextractor.results

        # ignore NaN
        for result in results:
            result.set_score_aggregate_method(ListStats.nonemean)

        self.assertAlmostEqual(results[0]['STRRED_feature_srred_score'],
                               1220.5679849999999,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_trred_score'],
                               50983.3097155,
                               places=4)
        self.assertAlmostEqual(results[0]['STRRED_feature_strred_score'],
                               62228595.6081,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_srred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_trred_score'],
                               0.0,
                               places=4)
        self.assertAlmostEqual(results[1]['STRRED_feature_strred_score'],
                               0.0,
                               places=4)

    def test_run_SpEED_matlab_fextractor(self):

        print 'test on running SpEED (Matlab) feature extractor...'
        ref_path, dis_path, asset, asset_original = set_default_576_324_videos_for_testing(
        )

        self.fextractor = SpEEDMatlabFeatureExtractor([asset, asset_original],
                                                      None,
                                                      fifo_mode=True,
                                                      result_store=None)

        self.fextractor.run(parallelize=True)
        results = self.fextractor.results
        # S-SpEED assertions on first frame
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_sspeed_2_scores'][0],
                               13.510418,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_sspeed_3_scores'][0],
                               7.211881,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_sspeed_4_scores'][0],
                               4.921501,
                               places=4)
        # T-SpEED assertions on third frame
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_tspeed_2_scores'][2],
                               32.994605,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_tspeed_3_scores'][2],
                               22.404285,
                               places=4)
        self.assertAlmostEqual(results[0].result_dict[self.fextractor.TYPE +
                                                      '_tspeed_4_scores'][2],
                               15.233468,
                               places=4)