本文整理汇总了Python中optimizer.Optimizer方法的典型用法代码示例。如果您正苦于以下问题:Python optimizer.Optimizer方法的具体用法?Python optimizer.Optimizer怎么用?Python optimizer.Optimizer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optimizer
的用法示例。
在下文中一共展示了optimizer.Optimizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_MultipleOptimizers
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_MultipleOptimizers(self):
# Make sure other score directories don't interfere with this test.
encoder_configuration.conf.override_scorepath_for_test([])
os.mkdir(os.path.join(encoder_configuration.conf.sysdir(), 'first_dir'))
os.mkdir(os.path.join(encoder_configuration.conf.sysdir(), 'second_dir'))
one_optimizer = optimizer.Optimizer(self.codec, scoredir='first_dir')
another_optimizer = optimizer.Optimizer(self.codec, scoredir='second_dir')
self.assertNotEqual(one_optimizer.context.cache.workdir,
another_optimizer.context.cache.workdir)
# Storing one encoding's score should not affect the other's.
one_encoding = one_optimizer.BestEncoding(100,
self.videofile)
one_encoding.Execute().Store()
another_encoding = another_optimizer.BestEncoding(100, self.videofile)
self.assertFalse(another_encoding.Result())
another_encoding.Recover()
self.assertFalse(another_encoding.Result())
示例2: __init__
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def __init__(self, filename, codec, score_function):
self.name = codec.name
self.videofile = encoder.Videofile(filename)
self.fileset = optimizer.FileAndRateSet()
self.fileset.AddFilesAndRates([filename],
fileset_picker.ChooseRates(self.videofile.width,
self.videofile.framerate))
self.my_optimizer = optimizer.Optimizer(codec,
file_set=self.fileset,
score_function=score_function)
self.filename = filename
self.encoder = self.my_optimizer.BestOverallEncoder()
if not self.encoder:
raise NotEnoughDataError('No overall encoder for %s on %s' %
(codec.name, filename))
self.points = None
示例3: test_OptimizeOverMultipleEncoders
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_OptimizeOverMultipleEncoders(self):
"""Run the optimizer for a few cycles with a real codec.
This may turn out to be an over-heavy test for every-checkin testing."""
my_fileset = test_tools.TestFileSet()
my_codec = vp8.Vp8Codec()
my_optimizer = optimizer.Optimizer(my_codec, my_fileset,
cache_class=encoder.EncodingDiskCache)
# Establish a baseline.
for bitrate, videofile_name in my_fileset.AllFilesAndRates():
videofile = encoder.Videofile(videofile_name)
my_encoding = my_optimizer.BestEncoding(bitrate, videofile)
my_encoding.Execute().Store()
# Try to improve it.
encoding_count = 0
while encoding_count < 10:
(bitrate, videofile_name) = random.choice(my_fileset.AllFilesAndRates())
videofile = encoder.Videofile(videofile_name)
next_encoding = my_optimizer.BestUntriedEncoding(bitrate, videofile)
if not next_encoding:
break
encoding_count += 1
next_encoding.Execute().Store()
示例4: ListMpegSingleConfigResults
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def ListMpegSingleConfigResults(codecs, datatable, score_function=None):
encoder_list = {}
optimizer_list = {}
for codec_name in codecs:
codec = pick_codec.PickCodec(codec_name)
my_optimizer = optimizer.Optimizer(codec,
score_function=score_function, file_set=mpeg_settings.MpegFiles())
optimizer_list[codec_name] = my_optimizer
encoder_list[codec_name] = my_optimizer.BestOverallEncoder()
for rate, filename in sorted(mpeg_settings.MpegFiles().AllFilesAndRates()):
videofile = encoder.Videofile(filename)
for codec_name in codecs:
if encoder_list[codec_name]:
my_encoding = encoder_list[codec_name].Encoding(rate, videofile)
my_encoding.Recover()
AddOneEncoding(codec_name, optimizer_list[codec_name],
my_encoding, videofile, datatable)
示例5: test_Passes
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_Passes(self):
"""This test checks that both 1-pass and 2-pass encoding works."""
codec = vp9.Vp9Codec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
start_encoder = codec.StartEncoder(my_optimizer.context)
encoder1 = encoder.Encoder(my_optimizer.context,
start_encoder.parameters.ChangeValue('passes', 1))
encoding1 = encoder1.Encoding(1000, videofile)
encoder2 = encoder.Encoder(my_optimizer.context,
start_encoder.parameters.ChangeValue('passes', 2))
encoding2 = encoder2.Encoding(1000, videofile)
encoding1.Execute()
encoding2.Execute()
self.assertTrue(encoding1.result)
self.assertTrue(encoding2.result)
示例6: load_opt_sched
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def load_opt_sched(train_config, model):
inf_params = model.inference_parameters()
gen_params = model.generative_parameters()
inf_opt = Optimizer(train_config['optimizer'], inf_params,
lr=train_config['inference_learning_rate'],
clip_grad_norm=train_config['clip_grad_norm'])
inf_sched = ExponentialLR(inf_opt.opt, 0.999)
gen_opt = Optimizer(train_config['optimizer'], gen_params,
lr=train_config['generation_learning_rate'],
clip_grad_norm=train_config['clip_grad_norm'])
gen_sched = ExponentialLR(gen_opt.opt, 0.999)
return (inf_opt, gen_opt), (inf_sched, gen_sched)
示例7: test_OneBlackFrame
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_OneBlackFrame(self):
codec = mjpeg.MotionJpegCodec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
# Motion JPEG generates a massive file, so give it a large target bitrate.
encoding = my_optimizer.BestEncoding(5000, videofile)
encoding.Execute()
self.assertLess(50.0, my_optimizer.Score(encoding))
示例8: test_ParametersSet
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_ParametersSet(self):
codec = mjpeg.MotionJpegCodec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
my_encoder = encoder.Encoder(my_optimizer.context,
encoder.OptionValueSet(codec.option_set, '-qmin 1 -qmax 2',
formatter=codec.option_formatter))
encoding = my_encoder.Encoding(5000, videofile)
encoding.Execute()
self.assertLess(50.0, my_optimizer.Score(encoding))
示例9: test_ParametersAdjusted
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_ParametersAdjusted(self):
codec = mjpeg.MotionJpegCodec()
my_optimizer = optimizer.Optimizer(codec)
my_encoder = encoder.Encoder(my_optimizer.context,
encoder.OptionValueSet(codec.option_set, '-qmin 2 -qmax 2',
formatter=codec.option_formatter))
self.assertEquals('2', my_encoder.parameters.GetValue('qmin'))
self.assertEquals('2', my_encoder.parameters.GetValue('qmax'))
# qmax is less than qmin. Should be adjusted to be above.
my_encoder = encoder.Encoder(my_optimizer.context,
encoder.OptionValueSet(codec.option_set, '-qmin 3 -qmax 2',
formatter=codec.option_formatter))
self.assertEquals('3', my_encoder.parameters.GetValue('qmin'))
self.assertEquals('3', my_encoder.parameters.GetValue('qmax'))
示例10: test_OneBlackFrame
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_OneBlackFrame(self):
codec = CopyingCodec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
encoding = my_optimizer.BestEncoding(1000, videofile)
encoding.Execute()
self.assertTrue(encoding.Result())
self.assertIn('encode_cputime', encoding.Result())
self.assertIn('encode_clocktime', encoding.Result())
self.assertIn('yuv_md5', encoding.Result())
示例11: test_VerifyOneBlackFrame
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_VerifyOneBlackFrame(self):
codec = CopyingCodec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
encoding = my_optimizer.BestEncoding(1000, videofile)
encoding.Execute()
self.assertTrue(encoding.VerifyEncode())
示例12: test_VerifyMd5Varies
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_VerifyMd5Varies(self):
codec = CorruptingCodec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
encoding = my_optimizer.BestEncoding(1000, videofile)
encoding.Execute()
first_md5 = encoding.Result()['yuv_md5']
encoding.Execute()
self.assertNotEqual(first_md5, encoding.Result()['yuv_md5'])
示例13: test_VerifyMatroskaFile
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_VerifyMatroskaFile(self):
codec = vp8.Vp8Codec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
encoding = my_optimizer.BestEncoding(1000, videofile)
encoding.Execute()
# Matroska files will be identical if generated within the same
# clock second. So wait a bit.
time.sleep(1)
self.assertTrue(encoding.VerifyEncode())
示例14: test_MatroskaFrameInfo
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_MatroskaFrameInfo(self):
codec = vp8.Vp8Codec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
encoding = my_optimizer.BestEncoding(1000, videofile)
encoding.Execute()
# This line comes from file_codec.Execute()
encodedfile = '%s/%s.%s' % (encoding.Workdir(), videofile.basename,
codec.extension)
frameinfo = file_codec.MatroskaFrameInfo(encodedfile)
self.assertEquals(len(frameinfo), 1)
self.assertGreater(os.path.getsize(encodedfile) * 8, frameinfo[0]['size'])
示例15: test_FfmpegFrameInfo
# 需要导入模块: import optimizer [as 别名]
# 或者: from optimizer import Optimizer [as 别名]
def test_FfmpegFrameInfo(self):
codec = vp8.Vp8Codec()
my_optimizer = optimizer.Optimizer(codec)
videofile = test_tools.MakeYuvFileWithOneBlankFrame(
'one_black_frame_1024_768_30.yuv')
encoding = my_optimizer.BestEncoding(1000, videofile)
encoding.Execute()
# This line comes from file_codec.Execute()
encodedfile = '%s/%s.%s' % (encoding.Workdir(), videofile.basename,
codec.extension)
frameinfo = file_codec.FfmpegFrameInfo(encodedfile)
self.assertEquals(len(frameinfo), 1)
self.assertGreater(os.path.getsize(encodedfile) * 8, frameinfo[0]['size'])