Python encoder.Encoder() Examples

The following are 30 code examples of encoder.Encoder(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module encoder , or try the search function .
Example #1
Source File: app.py    From Thespian with MIT License 6 votes vote down vote up
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)) 
Example #2
Source File: x264_unittest.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
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') 
Example #3
Source File: encoder.py    From micropython-stm-lib with MIT License 6 votes vote down vote up
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() 
Example #4
Source File: vp8_mpeg.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: encoder_unittest.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
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)) 
Example #6
Source File: encoder_unittest.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
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) 
Example #7
Source File: encoder_unittest.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
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) 
Example #8
Source File: encoder_unittest.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
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)) 
Example #9
Source File: vp9_unittest.py    From compare-codecs with Apache License 2.0 6 votes vote down vote up
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) 
Example #10
Source File: model.py    From Text-Classification-Models-Pytorch with MIT License 6 votes vote down vote up
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() 
Example #11
Source File: data.py    From captcha_trainer with Apache License 2.0 6 votes vote down vote up
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 
Example #12
Source File: app.py    From Thespian with MIT License 6 votes vote down vote up
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)) 
Example #13
Source File: style_transfer_net.py    From arbitrary_style_transfer with MIT License 5 votes vote down vote up
def __init__(self, encoder_weights_path):
        self.encoder = Encoder(encoder_weights_path)
        self.decoder = Decoder() 
Example #14
Source File: mjpeg.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(
      context, encoder.OptionValueSet(self.option_set, '',
                                      formatter=self.option_formatter)) 
Example #15
Source File: optimizer_unittest.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def EncoderFromParameterString(self, parameter_string):
    return encoder.Encoder(self.optimizer.context,
        encoder.OptionValueSet(self.optimizer.context.codec.option_set,
                               parameter_string)) 
Example #16
Source File: app.py    From Thespian with MIT License 5 votes vote down vote up
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),
                            ]
            # Tell each encoder the address of the analyzer
            for each in self.encoders:
                self.send(each, ('Analyzer', self.analyzer))
            import time
            time.sleep(0.2)

        # 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)) 
Example #17
Source File: x264_realtime.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(context, encoder.OptionValueSet(
      self.option_set,
      '--rc-lookahead 0 --preset faster --tune psnr --threads 4',
      formatter=self.option_formatter)) 
Example #18
Source File: optimizer_largetest.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(context,
                           encoder.OptionValueSet(self.option_set,
                                                  "--score=5")) 
Example #19
Source File: vp8_mpeg.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(context,
                           encoder.OptionValueSet(self.option_set,
                             self.start_encoder_parameters)) 
Example #20
Source File: ffmpeg.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(context, encoder.OptionValueSet(self.option_set, '')) 
Example #21
Source File: controller.py    From NAO_pytorch with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 encoder_layers,
                 encoder_vocab_size,
                 encoder_hidden_size,
                 encoder_dropout,
                 encoder_length,
                 source_length,
                 encoder_emb_size,
                 mlp_layers,
                 mlp_hidden_size,
                 mlp_dropout,
                 decoder_layers,
                 decoder_vocab_size,
                 decoder_hidden_size,
                 decoder_dropout,
                 decoder_length,
                 ):
        super(NAO, self).__init__()
        self.encoder = Encoder(
            encoder_layers,
            encoder_vocab_size,
            encoder_hidden_size,
            encoder_dropout,
            encoder_length,
            source_length,
            encoder_emb_size,
            mlp_layers,
            mlp_hidden_size,
            mlp_dropout,
        )
        self.decoder = Decoder(
            decoder_layers,
            decoder_vocab_size,
            decoder_hidden_size,
            decoder_dropout,
            decoder_length,
            encoder_length
        )

        self.flatten_parameters() 
Example #22
Source File: controller.py    From NAS-Benchmark with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 encoder_layers,
                 encoder_vocab_size,
                 encoder_hidden_size,
                 encoder_dropout,
                 encoder_length,
                 source_length,
                 encoder_emb_size,
                 mlp_layers,
                 mlp_hidden_size,
                 mlp_dropout,
                 decoder_layers,
                 decoder_vocab_size,
                 decoder_hidden_size,
                 decoder_dropout,
                 decoder_length,
                 ):
        super(NAO, self).__init__()
        self.encoder = Encoder(
            encoder_layers,
            encoder_vocab_size,
            encoder_hidden_size,
            encoder_dropout,
            encoder_length,
            source_length,
            encoder_emb_size,
            mlp_layers,
            mlp_hidden_size,
            mlp_dropout,
        )
        self.decoder = Decoder(
            decoder_layers,
            decoder_vocab_size,
            decoder_hidden_size,
            decoder_dropout,
            decoder_length,
            encoder_length
        )

        self.init_parameters()
        self.flatten_parameters() 
Example #23
Source File: predict_testing.py    From captcha_trainer with Apache License 2.0 5 votes vote down vote up
def __init__(self, project_name):
        self.model_conf = ModelConfig(project_name=project_name)
        self.encoder = Encoder(model_conf=self.model_conf, mode=RunMode.Predict) 
Example #24
Source File: x265.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(context, encoder.OptionValueSet(self.option_set,
        '')) 
Example #25
Source File: controller.py    From NAO_pytorch with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 encoder_layers,
                 encoder_vocab_size,
                 encoder_hidden_size,
                 encoder_dropout,
                 encoder_length,
                 source_length,
                 encoder_emb_size,
                 mlp_layers,
                 mlp_hidden_size,
                 mlp_dropout,
                 decoder_layers,
                 decoder_vocab_size,
                 decoder_hidden_size,
                 decoder_dropout,
                 decoder_length,
                 ):
        super(NAO, self).__init__()
        self.encoder = Encoder(
            encoder_layers,
            encoder_vocab_size,
            encoder_hidden_size,
            encoder_dropout,
            encoder_length,
            source_length,
            encoder_emb_size,
            mlp_layers,
            mlp_hidden_size,
            mlp_dropout,
        )
        self.decoder = Decoder(
            decoder_layers,
            decoder_vocab_size,
            decoder_hidden_size,
            decoder_dropout,
            decoder_length,
            encoder_length
        )

        self.flatten_parameters() 
Example #26
Source File: vp9_unittest.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def test_EncoderVersion(self):
    codec = vp9.Vp9Codec()
    self.assertRegexpMatches(codec.EncoderVersion(),
                             r'WebM Project VP9 Encoder') 
Example #27
Source File: h261.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(context, encoder.OptionValueSet(self.option_set, '')) 
Example #28
Source File: x264.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def StartEncoder(self, context):
    return encoder.Encoder(context, encoder.OptionValueSet(
      self.option_set,
      '--preset slow --tune psnr --threads 1',
      formatter=self.option_formatter)) 
Example #29
Source File: encoder_unittest.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
def test_Changevalue(self):
    config = encoder.OptionValueSet(
        encoder.OptionSet(encoder.Option('foo', ['foo', 'bar'])),
        '--foo=foo')
    context = encoder.Context(DummyCodec())
    my_encoder = encoder.Encoder(context, config)
    next_encoder = my_encoder.ChangeValue('foo', 'bar')
    self.assertEquals(next_encoder.parameters, '--foo=bar') 
Example #30
Source File: mjpeg_unittest.py    From compare-codecs with Apache License 2.0 5 votes vote down vote up
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))