當前位置: 首頁>>代碼示例>>Python>>正文


Python optimizer.Optimizer方法代碼示例

本文整理匯總了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()) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:20,代碼來源:optimizer_unittest.py

示例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 
開發者ID:google,項目名稱:compare-codecs,代碼行數:18,代碼來源:graph_metrics.py

示例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() 
開發者ID:google,項目名稱:compare-codecs,代碼行數:25,代碼來源:optimizer_largetest.py

示例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) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:19,代碼來源:visual_metrics.py

示例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) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:19,代碼來源:vp9_unittest.py

示例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) 
開發者ID:joelouismarino,項目名稱:amortized-variational-filtering,代碼行數:18,代碼來源:load_opt_sched.py

示例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)) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:11,代碼來源:mjpeg_unittest.py

示例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)) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:13,代碼來源:mjpeg_unittest.py

示例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')) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:16,代碼來源:mjpeg_unittest.py

示例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()) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:13,代碼來源:file_codec_unittest.py

示例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()) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:10,代碼來源:file_codec_unittest.py

示例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']) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:12,代碼來源:file_codec_unittest.py

示例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()) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:13,代碼來源:file_codec_unittest.py

示例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']) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:15,代碼來源:file_codec_unittest.py

示例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']) 
開發者ID:google,項目名稱:compare-codecs,代碼行數:15,代碼來源:file_codec_unittest.py


注:本文中的optimizer.Optimizer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。