Пример #1
0
    def setUp(self):

        train_dataset_path = VmafConfig.test_resource_path(
            'test_image_dataset_diffdim.py')
        train_dataset = import_python_file(train_dataset_path)
        train_assets = read_dataset(train_dataset)

        self.h5py_filepath = VmafConfig.workdir_path('test.hdf5')
        self.h5py_file = DisYUVRawVideoExtractor.open_h5py_file(
            self.h5py_filepath)
        optional_dict2 = {'h5py_file': self.h5py_file}

        _, self.features = run_executors_in_parallel(
            DisYUVRawVideoExtractor,
            train_assets,
            fifo_mode=True,
            delete_workdir=True,
            parallelize=
            False,  # CAN ONLY USE SERIAL MODE FOR DisYRawVideoExtractor
            result_store=None,
            optional_dict=None,
            optional_dict2=optional_dict2,
        )

        self.model_filename = VmafConfig.workspace_path(
            "model", "test_save_load.pkl")
Пример #2
0
    def test_run_dis_yuv_raw_video_extractor_parallel(self):
        print 'test on running dis YUV raw video 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=1,
                      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=2,
                      workdir_root=VmafConfig.workdir_path(),
                      ref_path=ref_path,
                      dis_path=ref_path,
                      asset_dict={'width':576, 'height':324})

        h5py_file = DisYUVRawVideoExtractor.open_h5py_file(self.h5py_filepath)

        self.fextractor = DisYUVRawVideoExtractor(
            [asset, asset_original], None, fifo_mode=False,
            optional_dict={'channels': 'yu'},
            optional_dict2={'h5py_file': h5py_file}
        )

        with self.assertRaises(AssertionError):
            self.fextractor.run(parallelize=True)

        DisYUVRawVideoExtractor.close_h5py_file(h5py_file)
Пример #3
0
    def test_run_parallel_dis_y_fextractor(self):
        print 'test on running dis YUV raw video extractor in parallel (disabled)...'
        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=1,
                      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=2,
                               workdir_root=VmafConfig.workdir_path(),
                               ref_path=ref_path,
                               dis_path=ref_path,
                               asset_dict={
                                   'width': 576,
                                   'height': 324
                               })

        h5py_file = DisYUVRawVideoExtractor.open_h5py_file(self.h5py_filepath)
        optional_dict2 = {'h5py_file': h5py_file}

        fextractor = DisYUVRawVideoExtractor([asset, asset_original],
                                             None,
                                             fifo_mode=True,
                                             delete_workdir=True,
                                             result_store=None,
                                             optional_dict={'channels': 'yu'},
                                             optional_dict2=optional_dict2)
        self.fextractors = [fextractor]
        fextractor.run(parallelize=False
                       )  # Can't run parallel: can't pickle FileID objects
        results = fextractor.results

        self.assertAlmostEqual(np.mean(results[0]['dis_y']),
                               61.332006579182384,
                               places=4)
        self.assertAlmostEquals(np.mean(results[1]['dis_y']),
                                59.788567297525148,
                                places=4)
        self.assertAlmostEqual(np.mean(results[0]['dis_u']),
                               115.23227407335962,
                               places=4)
        self.assertAlmostEquals(np.mean(results[1]['dis_u']),
                                114.49701717535437,
                                places=4)

        with self.assertRaises(KeyError):
            np.mean(results[0]['dis_v'])

        DisYUVRawVideoExtractor.close_h5py_file(h5py_file)
Пример #4
0
    def test_run_dis_yuv_raw_video_extractor_parallel(self):
        print 'test on running dis YUV raw video 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=1,
                      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=2,
                      workdir_root=VmafConfig.workdir_path(),
                      ref_path=ref_path,
                      dis_path=ref_path,
                      asset_dict={'width':576, 'height':324})

        h5py_file = DisYUVRawVideoExtractor.open_h5py_file(self.h5py_filepath)

        self.fextractor = DisYUVRawVideoExtractor(
            [asset, asset_original], None, fifo_mode=False,
            optional_dict={'channels': 'yu'},
            optional_dict2={'h5py_file': h5py_file}
        )

        with self.assertRaises(AssertionError):
            self.fextractor.run(parallelize=True)

        DisYUVRawVideoExtractor.close_h5py_file(h5py_file)
Пример #5
0
    def test_run_dis_yuv_raw_video_extractor(self):
        print('test on running dis YUV raw video 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=1,
                      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=2,
                               workdir_root=VmafConfig.workdir_path(),
                               ref_path=ref_path,
                               dis_path=ref_path,
                               asset_dict={
                                   'width': 576,
                                   'height': 324
                               })

        h5py_file = DisYUVRawVideoExtractor.open_h5py_file(self.h5py_filepath)

        self.fextractor = DisYUVRawVideoExtractor(
            [asset, asset_original],
            None,
            fifo_mode=False,
            optional_dict={'channels': 'yu'},
            optional_dict2={'h5py_file': h5py_file})

        self.fextractor.run()

        results = self.fextractor.results

        self.assertAlmostEqual(np.mean(results[0]['dis_y']),
                               61.332006579182384,
                               places=4)
        self.assertAlmostEqual(np.mean(results[1]['dis_y']),
                               59.788567297525148,
                               places=4)
        self.assertAlmostEqual(np.mean(results[0]['dis_u']),
                               115.23227407335962,
                               places=4)
        self.assertAlmostEqual(np.mean(results[1]['dis_u']),
                               114.49701717535437,
                               places=4)

        with self.assertRaises(KeyError):
            np.mean(results[0]['dis_v'])

        DisYUVRawVideoExtractor.close_h5py_file(h5py_file)
Пример #6
0
    def setUp(self):
        train_dataset_path = VmafConfig.test_resource_path("test_image_dataset_diffdim.py")
        train_dataset = import_python_file(train_dataset_path)
        train_assets = read_dataset(train_dataset)

        self.h5py_filepath = VmafConfig.workdir_path('test.hdf5')
        self.h5py_file = DisYUVRawVideoExtractor.open_h5py_file(self.h5py_filepath)
        optional_dict2 = {'h5py_file': self.h5py_file}

        fextractor = DisYUVRawVideoExtractor(
            train_assets,
            None,
            fifo_mode=True,
            delete_workdir=True,
            result_store=None,
            optional_dict=None,
            optional_dict2=optional_dict2,
        )
        fextractor.run(parallelize=False) # CAN ONLY USE SERIAL MODE FOR DisYRawVideoExtractor
        self.features = fextractor.results
Пример #7
0
    def setUp(self):
        train_dataset_path = VmafConfig.test_resource_path("test_image_dataset_diffdim.py")
        train_dataset = import_python_file(train_dataset_path)
        train_assets = read_dataset(train_dataset)

        self.h5py_filepath = VmafConfig.workdir_path('test.hdf5')
        self.h5py_file = DisYUVRawVideoExtractor.open_h5py_file(self.h5py_filepath)
        optional_dict2 = {'h5py_file': self.h5py_file}

        fextractor = DisYUVRawVideoExtractor(
            train_assets,
            None,
            fifo_mode=True,
            delete_workdir=True,
            result_store=None,
            optional_dict=None,
            optional_dict2=optional_dict2,
        )
        fextractor.run(parallelize=False) # CAN ONLY USE SERIAL MODE FOR DisYRawVideoExtractor
        self.features = fextractor.results
Пример #8
0
    def test_run_parallel_dis_y_fextractor(self):
        print 'test on running dis YUV raw video extractor in parallel (disabled)...'
        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=1,
                      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=2,
                      workdir_root=VmafConfig.workdir_path(),
                      ref_path=ref_path,
                      dis_path=ref_path,
                      asset_dict={'width':576, 'height':324})

        h5py_file = DisYUVRawVideoExtractor.open_h5py_file(self.h5py_filepath)
        optional_dict2 = {'h5py_file': h5py_file}

        fextractor = DisYUVRawVideoExtractor(
            [asset, asset_original],
            None,
            fifo_mode=True,
            delete_workdir=True,
            result_store=None,
            optional_dict={'channels': 'yu'},
            optional_dict2=optional_dict2
        )
        self.fextractors = [fextractor]
        fextractor.run(parallelize=False) # Can't run parallel: can't pickle FileID objects
        results = fextractor.results

        self.assertAlmostEqual(np.mean(results[0]['dis_y']), 61.332006579182384, places=4)
        self.assertAlmostEquals(np.mean(results[1]['dis_y']), 59.788567297525148, places=4)
        self.assertAlmostEqual(np.mean(results[0]['dis_u']), 115.23227407335962, places=4)
        self.assertAlmostEquals(np.mean(results[1]['dis_u']), 114.49701717535437, places=4)

        with self.assertRaises(KeyError):
            np.mean(results[0]['dis_v'])

        DisYUVRawVideoExtractor.close_h5py_file(h5py_file)
Пример #9
0
    def setUp(self):
        train_dataset_path = config.ROOT + '/python/test/resource/test_image_dataset_diffdim.py'
        train_dataset = import_python_file(train_dataset_path)
        train_assets = read_dataset(train_dataset)

        self.h5py_filepath = config.ROOT + '/workspace/workdir/test.hdf5'
        self.h5py_file = DisYUVRawVideoExtractor.open_h5py_file(
            self.h5py_filepath)
        optional_dict2 = {'h5py_file': self.h5py_file}

        _, self.features = run_executors_in_parallel(
            DisYUVRawVideoExtractor,
            train_assets,
            fifo_mode=True,
            delete_workdir=True,
            parallelize=
            False,  # CAN ONLY USE SERIAL MODE FOR DisYRawVideoExtractor
            result_store=None,
            optional_dict=None,
            optional_dict2=optional_dict2,
        )
Пример #10
0
num_test = 50
n_epochs = 30
seed = 0 # None

# read input dataset
dataset_path = config.ROOT + '/resource/dataset/BSDS500_noisy_dataset.py'
dataset = import_python_file(dataset_path)
assets = read_dataset(dataset)

# shuffle assets
np.random.seed(seed)
np.random.shuffle(assets)
assets = assets[:(num_train + num_test)]

raw_video_h5py_filepath = config.ROOT + '/workspace/workdir/rawvideo.hdf5'
raw_video_h5py_file = DisYUVRawVideoExtractor.open_h5py_file(raw_video_h5py_filepath)

print '======================== Extract raw YUVs =============================='

_, raw_yuvs = run_executors_in_parallel(
    DisYUVRawVideoExtractor,
    assets,
    fifo_mode=True,
    delete_workdir=True,
    parallelize=False, # CAN ONLY USE SERIAL MODE FOR DisYRawVideoExtractor
    result_store=None,
    optional_dict=None,
    optional_dict2={'h5py_file': raw_video_h5py_file})

patch_h5py_filepath = config.ROOT + '/workspace/workdir/patch.hdf5'
patch_h5py_file = ToddNoiseClassifierTrainTestModel.open_h5py_file(patch_h5py_filepath)
Пример #11
0
def main():
    # parameters
    num_train = 500
    num_test = 50
    n_epochs = 30
    seed = 0  # None

    # read input dataset
    dataset_path = VmafConfig.resource_path('dataset',
                                            'BSDS500_noisy_dataset.py')
    dataset = import_python_file(dataset_path)
    assets = read_dataset(dataset)

    # shuffle assets
    np.random.seed(seed)
    np.random.shuffle(assets)
    assets = assets[:(num_train + num_test)]

    raw_video_h5py_filepath = VmafConfig.workdir_path('rawvideo.hdf5')
    raw_video_h5py_file = DisYUVRawVideoExtractor.open_h5py_file(
        raw_video_h5py_filepath)

    print(
        '======================== Extract raw YUVs =============================='
    )

    _, raw_yuvs = run_executors_in_parallel(
        DisYUVRawVideoExtractor,
        assets,
        fifo_mode=True,
        delete_workdir=True,
        parallelize=False,  # CAN ONLY USE SERIAL MODE FOR DisYRawVideoExtractor
        result_store=None,
        optional_dict=None,
        optional_dict2={'h5py_file': raw_video_h5py_file})

    patch_h5py_filepath = VmafConfig.workdir_path('patch.hdf5')
    patch_h5py_file = ToddNoiseClassifierTrainTestModel.open_h5py_file(
        patch_h5py_filepath)
    model = ToddNoiseClassifierTrainTestModel(
        param_dict={
            'seed': seed,
            'n_epochs': n_epochs,
        },
        logger=None,
        optional_dict2={ # for options that won't impact the result
            # 'checkpoints_dir': VmafConfig.workspace_path('checkpoints_dir'),
            'h5py_file': patch_h5py_file,
        })

    print(
        '============================ Train model ==============================='
    )
    xys = ToddNoiseClassifierTrainTestModel.get_xys_from_results(
        raw_yuvs[:num_train])
    model.train(xys)

    print(
        '=========================== Evaluate model ============================='
    )
    xs = ToddNoiseClassifierTrainTestModel.get_xs_from_results(
        raw_yuvs[num_train:])
    ys = ToddNoiseClassifierTrainTestModel.get_ys_from_results(
        raw_yuvs[num_train:])
    result = model.evaluate(xs, ys)

    print("")
    print("f1 test %g, errorrate test %g" %
          (result['f1'], result['errorrate']))

    # tear down
    DisYUVRawVideoExtractor.close_h5py_file(raw_video_h5py_file)
    ToddNoiseClassifierTrainTestModel.close_h5py_file(patch_h5py_file)
    os.remove(raw_video_h5py_filepath)
    os.remove(patch_h5py_filepath)

    print('Done.')
Пример #12
0
num_test = 50
n_epochs = 30
seed = 0 # None

# read input dataset
dataset_path = VmafConfig.resource_path('dataset', 'BSDS500_noisy_dataset.py')
dataset = import_python_file(dataset_path)
assets = read_dataset(dataset)

# shuffle assets
np.random.seed(seed)
np.random.shuffle(assets)
assets = assets[:(num_train + num_test)]

raw_video_h5py_filepath = VmafConfig.workdir_path('rawvideo.hdf5')
raw_video_h5py_file = DisYUVRawVideoExtractor.open_h5py_file(raw_video_h5py_filepath)

print '======================== Extract raw YUVs =============================='

_, raw_yuvs = run_executors_in_parallel(
    DisYUVRawVideoExtractor,
    assets,
    fifo_mode=True,
    delete_workdir=True,
    parallelize=False, # CAN ONLY USE SERIAL MODE FOR DisYRawVideoExtractor
    result_store=None,
    optional_dict=None,
    optional_dict2={'h5py_file': raw_video_h5py_file})

patch_h5py_filepath = VmafConfig.workdir_path('patch.hdf5')
patch_h5py_file = ToddNoiseClassifierTrainTestModel.open_h5py_file(patch_h5py_filepath)