def tearDown(self): if hasattr(self, 'h5py_file'): DisYUVRawVideoExtractor.close_h5py_file(self.h5py_file) if os.path.exists(self.h5py_filepath): os.remove(self.h5py_filepath) if os.path.exists(self.model_filename): os.remove(self.model_filename)
def tearDown(self): if hasattr(self, 'raw_video_h5py_file'): DisYUVRawVideoExtractor.close_h5py_file(self.raw_video_h5py_file) if os.path.exists(self.raw_video_h5py_filepath): os.remove(self.raw_video_h5py_filepath) if os.path.exists(self.patch_h5py_filepath): os.remove(self.patch_h5py_filepath) if hasattr(self, 'model'): self.model.delete(self.model_filename)
def test_run_dis_yuv_raw_video_extractor(self): print 'test on running dis YUV raw video extractor...' ref_path = config.ROOT + "/resource/yuv/src01_hrc00_576x324.yuv" dis_path = config.ROOT + "/resource/yuv/src01_hrc01_576x324.yuv" asset = Asset(dataset="test", content_id=0, asset_id=1, workdir_root=config.ROOT + "/workspace/workdir", 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=config.ROOT + "/workspace/workdir", 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.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)
def test_run_parallel_dis_y_fextractor(self): print 'test on running dis YUV raw video extractor in parallel (disabled)...' ref_path = config.ROOT + "/resource/yuv/src01_hrc00_576x324.yuv" dis_path = config.ROOT + "/resource/yuv/src01_hrc01_576x324.yuv" asset = Asset(dataset="test", content_id=0, asset_id=1, workdir_root=config.ROOT + "/workspace/workdir", 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=config.ROOT + "/workspace/workdir", 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} self.fextractors, results = run_executors_in_parallel( DisYUVRawVideoExtractor, [asset, asset_original], fifo_mode=True, delete_workdir=True, parallelize=False, # Can't run parallel: can't pickle FileID objects result_store=None, optional_dict={'channels': 'yu'}, optional_dict2=optional_dict2) 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)
def test_run_dis_yuv_raw_video_extractor_parallel(self): print 'test on running dis YUV raw video extractor...' ref_path = config.ROOT + "/resource/yuv/src01_hrc00_576x324.yuv" dis_path = config.ROOT + "/resource/yuv/src01_hrc01_576x324.yuv" asset = Asset(dataset="test", content_id=0, asset_id=1, workdir_root=config.ROOT + "/workspace/workdir", 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=config.ROOT + "/workspace/workdir", 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)
model = ToddNoiseClassifierTrainTestModel( param_dict={ 'seed': seed, 'n_epochs': n_epochs, }, logger=None, optional_dict2={ # for options that won't impact the result # 'checkpoints_dir': config.ROOT + '/workspace/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.'