本文整理汇总了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()
示例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))
示例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)
示例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)
示例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))
示例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')
示例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)
示例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)
示例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()
示例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
示例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))
示例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))
示例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'))
示例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'))
示例15: StartEncoder
# 需要导入模块: import encoder [as 别名]
# 或者: from encoder import Encoder [as 别名]
def StartEncoder(self, context):
return encoder.Encoder(context, encoder.OptionValueSet(None, ''))