当前位置: 首页>>代码示例>>Python>>正文


Python encoder.Encoder方法代码示例

本文整理汇总了Python中encoder.Encoder方法的典型用法代码示例。如果您正苦于以下问题:Python encoder.Encoder方法的具体用法?Python encoder.Encoder怎么用?Python encoder.Encoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在encoder的用法示例。


在下文中一共展示了encoder.Encoder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def test(enc=None, **kwargs):
    from time import sleep_ms
    rate = kwargs.pop('rate', 20)

    if not isinstance(enc, Encoder):
        cls = kwargs.pop('encoder_cls', Encoder)
        kwargs.setdefault('pin_clk', 12)
        kwargs.setdefault('pin_dt', 14)
        kwargs.setdefault('clicks', 4)
        enc = cls(**kwargs)

    oldval = 0
    try:
        while True:
            val = enc.value
            if oldval != val:
                print(val)
                oldval = val

            enc.cur_accel = max(0, enc.cur_accel - enc.accel)
            sleep_ms(1000 // rate)
    except:
        enc.close() 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:25,代码来源:encoder.py

示例2: testStoreMultipleEncodings

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def testStoreMultipleEncodings(self):
    context = StorageOnlyContext()
    cache = encoder.EncodingDiskCache(context)
    # This particular test needs the context to know about the cache.
    context.cache = cache
    my_encoder = encoder.Encoder(
        context,
        encoder.OptionValueSet(encoder.OptionSet(), '--parameters'))
    cache.StoreEncoder(my_encoder)
    videofile = encoder.Videofile('x/foo_640_480_20.yuv')
    my_encoding = encoder.Encoding(my_encoder, 123, videofile)

    testresult = {'foo': 'bar'}
    my_encoding.result = testresult
    cache.StoreEncoding(my_encoding)
    my_encoding = encoder.Encoding(my_encoder, 246, videofile)
    my_encoding.result = testresult
    cache.StoreEncoding(my_encoding)
    result = cache.AllScoredRates(my_encoder, videofile)
    self.assertEquals(2, len(result))
    result = cache.AllScoredEncodings(123, videofile)
    self.assertEquals(1, len(result)) 
开发者ID:google,项目名称:compare-codecs,代码行数:24,代码来源:encoder_unittest.py

示例3: testReadResultFromAlternateDir

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def testReadResultFromAlternateDir(self):
    context = StorageOnlyContext()
    otherdir_path = os.path.join(encoder_configuration.conf.sysdir(),
                                 'otherdir')
    os.mkdir(otherdir_path)
    cache = encoder.EncodingDiskCache(context)
    other_cache = encoder.EncodingDiskCache(context, scoredir='otherdir')
    my_encoder = encoder.Encoder(
        context,
        encoder.OptionValueSet(encoder.OptionSet(), '--parameters'))
    cache.StoreEncoder(my_encoder)
    videofile = encoder.Videofile('x/foo_640_480_20.yuv')
    my_encoding = encoder.Encoding(my_encoder, 123, videofile)

    testresult = {'foo': 'bar'}
    my_encoding.result = testresult
    cache.StoreEncoding(my_encoding)
    my_encoding.result = None
    result = other_cache.ReadEncodingResult(my_encoding)
    self.assertIsNone(result)
    shutil.rmtree(otherdir_path)
    shutil.copytree(encoder_configuration.conf.workdir(), otherdir_path)
    result = other_cache.ReadEncodingResult(my_encoding)
    self.assertEquals(result, testresult) 
开发者ID:google,项目名称:compare-codecs,代码行数:26,代码来源:encoder_unittest.py

示例4: testAllScoredEncodingsForEncoder

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def testAllScoredEncodingsForEncoder(self):
    context = StorageOnlyContext()
    cache = encoder.EncodingDiskCache(context)
    # This particular test needs the context to know about the cache.
    context.cache = cache
    my_encoder = encoder.Encoder(
        context,
        encoder.OptionValueSet(encoder.OptionSet(), '--parameters'))
    cache.StoreEncoder(my_encoder)
    # Cache should start off empty.
    self.assertFalse(cache.AllScoredEncodingsForEncoder(my_encoder))
    videofile = encoder.Videofile('x/foo_640_480_20.yuv')
    my_encoding = encoder.Encoding(my_encoder, 123, videofile)
    testresult = {'foo': 'bar'}
    my_encoding.result = testresult
    cache.StoreEncoding(my_encoding)
    result = cache.AllScoredEncodingsForEncoder(my_encoder)
    self.assertTrue(result)
    self.assertEquals(1, len(result))
    # The resulting videofile should have a basename = filename,
    # because synthesizing filenames from result files loses directory
    # information.
    self.assertEquals('foo_640_480_20.yuv', result[0].videofile.filename) 
开发者ID:google,项目名称:compare-codecs,代码行数:25,代码来源:encoder_unittest.py

示例5: testStorageWithMergedBitrates

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def testStorageWithMergedBitrates(self):
    context = StorageOnlyContext()
    context.codec = StorageOnlyCodecWithNoBitrate()
    cache = encoder.EncodingDiskCache(context)
    # This particular test needs the context to know about the cache.
    context.cache = cache
    my_encoder = encoder.Encoder(
        context,
        encoder.OptionValueSet(encoder.OptionSet(), '--parameters'))
    cache.StoreEncoder(my_encoder)
    videofile = encoder.Videofile('x/foo_640_480_20.yuv')
    my_encoding = encoder.Encoding(my_encoder, 123, videofile)

    testresult = {'foo': 'bar'}
    my_encoding.result = testresult
    cache.StoreEncoding(my_encoding)
    my_encoding = encoder.Encoding(my_encoder, 246, videofile)
    my_encoding.result = testresult
    cache.StoreEncoding(my_encoding)
    result = cache.AllScoredRates(my_encoder, videofile)
    self.assertEquals(1, len(result))
    result = cache.AllScoredEncodings(123, videofile)
    self.assertEquals(1, len(result)) 
开发者ID:google,项目名称:compare-codecs,代码行数:25,代码来源:encoder_unittest.py

示例6: test_VbvMaxrateFlag

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def test_VbvMaxrateFlag(self):
    codec = x264.X264Codec()
    context = encoder.Context(codec)
    my_encoder = codec.StartEncoder(context)
    videofile = test_tools.MakeYuvFileWithOneBlankFrame(
        'one_black_frame_1024_768_30.yuv')
    encoding = my_encoder.Encoding(1000, videofile)
    # The start encoder should have no bitrate.
    commandline = encoding.EncodeCommandLine()
    self.assertNotRegexpMatches(commandline, 'vbv-maxrate')
    # Add in the use-vbv-maxrate parameter.
    new_encoder = encoder.Encoder(context,
        my_encoder.parameters.ChangeValue('use-vbv-maxrate', 'use-vbv-maxrate'))
    encoding = new_encoder.Encoding(1000, videofile)
    commandline = encoding.EncodeCommandLine()
    # vbv-maxrate should occur, but not use-vbv-maxrate.
    self.assertRegexpMatches(commandline, '--vbv-maxrate 1000 ')
    self.assertNotRegexpMatches(commandline, 'use-vbv-maxrate') 
开发者ID:google,项目名称:compare-codecs,代码行数:20,代码来源:x264_unittest.py

示例7: SuggestTweak

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def SuggestTweak(self, encoding):
    """Suggest a tweak based on an encoding result.
    For fixed QP, suggest increasing min-q when bitrate is too high, otherwise
    suggest decreasing it.
    If a parameter is already at the limit, go to the next one."""
    if not encoding.result:
      return None

    parameters = self._SuggestTweakToName(encoding, 'fixed-q')
    if not parameters:
      parameters = self._SuggestTweakToName(encoding, 'gold-q')
    if not parameters:
      parameters = self._SuggestTweakToName(encoding, 'key-q')
    if not parameters:
      return None
    parameters = self.ConfigurationFixups(parameters)
    return encoder.Encoding(encoder.Encoder(encoding.context, parameters),
                    encoding.bitrate, encoding.videofile) 
开发者ID:google,项目名称:compare-codecs,代码行数:20,代码来源:vp8_mpeg.py

示例8: test_Passes

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [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

示例9: __init__

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def __init__(self, config, src_vocab):
        super(Transformer, self).__init__()
        self.config = config
        
        h, N, dropout = self.config.h, self.config.N, self.config.dropout
        d_model, d_ff = self.config.d_model, self.config.d_ff
        
        attn = MultiHeadedAttention(h, d_model)
        ff = PositionwiseFeedForward(d_model, d_ff, dropout)
        position = PositionalEncoding(d_model, dropout)
        
        self.encoder = Encoder(EncoderLayer(config.d_model, deepcopy(attn), deepcopy(ff), dropout), N)
        self.src_embed = nn.Sequential(Embeddings(config.d_model, src_vocab), deepcopy(position)) #Embeddings followed by PE

        # Fully-Connected Layer
        self.fc = nn.Linear(
            self.config.d_model,
            self.config.output_size
        )
        
        # Softmax non-linearity
        self.softmax = nn.Softmax() 
开发者ID:AnubhavGupta3377,项目名称:Text-Classification-Models-Pytorch,代码行数:24,代码来源:model.py

示例10: __init__

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def __init__(self, model_conf: ModelConfig, mode: RunMode, ran_captcha=None):
        """
        :param model_conf: 工程配置
        :param mode: 运行模式(区分:训练/验证)
        """
        self.model_conf = model_conf
        self.mode = mode
        self.path_map = {
            RunMode.Trains: self.model_conf.trains_path[DatasetType.TFRecords],
            RunMode.Validation: self.model_conf.validation_path[DatasetType.TFRecords]
        }
        self.batch_map = {
            RunMode.Trains: self.model_conf.batch_size,
            RunMode.Validation: self.model_conf.validation_batch_size
        }
        self.data_dir = self.path_map[mode]
        self.next_element = None
        self.image_path = []
        self.label_list = []
        self._label_list = []
        self._size = 0
        self.encoder = Encoder(self.model_conf, self.mode)
        self.ran_captcha = ran_captcha 
开发者ID:kerlomz,项目名称:captcha_trainer,代码行数:25,代码来源:data.py

示例11: receiveMsg_str

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def receiveMsg_str(self, message, sender):
        """Primary entry point for receiving strings that are to be encoded
           and analyzed.
        """
        # First, make sure the analyzer and encoders are present
        if not self.analyzer:
            self.analyzer = self.createActor(Analyzer)
            self.encoders = [ self.createActor(Encoder),
                              self.createActor(Base64Encoder),
                              self.createActor(MorseEncoder),
                              self.createActor(Rot13Encoder),
                            ]

        # Now send the input string to each encoder.  The encoders
        # already have the analyzer address to forward the result
        # to, but include the original sender's address so that
        # the analyzer knows where to send the response.

        for each in self.encoders:
            self.send(each,
                      EncodeThis(message, sender, self.analyzer)) 
开发者ID:thespianpy,项目名称:Thespian,代码行数:23,代码来源:app.py

示例12: test_ParametersSet

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [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

示例13: test_ParametersAdjusted

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [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

示例14: StartEncoder

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def StartEncoder(self, context):
    return encoder.Encoder(context, encoder.OptionValueSet(self.option_set,
      '--lag-in-frames=0 '
      '--kf-min-dist=3000 '
      '--kf-max-dist=3000 --cpu-used=0 --static-thresh=0 '
      '--token-parts=1 --end-usage=cbr --min-q=2 --max-q=56 '
      '--undershoot-pct=100 --overshoot-pct=15 --buf-sz=1000 '
      '--buf-initial-sz=800 --buf-optimal-sz=1000 --max-intra-rate=1200 '
      '--resize-allowed=0 --drop-frame=0 '
      '--passes=1 --good --noise-sensitivity=0')) 
开发者ID:google,项目名称:compare-codecs,代码行数:12,代码来源:vp8.py

示例15: StartEncoder

# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def StartEncoder(self, context):
    return encoder.Encoder(context, encoder.OptionValueSet(None, '')) 
开发者ID:google,项目名称:compare-codecs,代码行数:4,代码来源:file_codec_unittest.py


注:本文中的encoder.Encoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。