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


Python decoder.Decoder类代码示例

本文整理汇总了Python中decoder.Decoder的典型用法代码示例。如果您正苦于以下问题:Python Decoder类的具体用法?Python Decoder怎么用?Python Decoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: get_n_best_lists

def get_n_best_lists(initial_params, n, args):
    sys.stderr.write("Getting n best lists...\n")
    num_songs_translated = 0
    n_best_lists = {}
    i = 0
    f = open(args.training_songs, "r")
    for path in f:
        path = path.strip()
        if not path:
            continue
        training_song = converter.parse(path);
        num_songs_translated += 1
        transpose(training_song, "C")
        sys.stderr.write("transposed " + path + "\n")
        lm = LanguageModel(args.harmony, "%s/%s_language_model.txt" % (args.model_directory, args.harmony))
        tms = []
        melodies = args.melodies.split(",")
        for melody in melodies:
            phrases = "%s/%s_%s_translation_model_rhythm.txt" % (args.model_directory, melody, args.harmony)
            notes = "%s/%s_%s_translation_model.txt" % (args.model_directory, melody, args.harmony)
            tm = TranslationModel(melody, args.harmony, phrases, notes)
            tms.append(tm)
        d = Decoder([(melody, training_song.parts[melody]) for melody in melodies], 
                    lm, tms,
                    tm_phrase_weight=initial_params[0], tm_notes_weight=initial_params[1],
                    lm_weight=initial_params[2])
        try:
            hyps = d.decode(n)
            n_best_lists[path] = hyps
            sys.stderr.write("decoded " + path + "\n")
            i += 1
        except Exception as e:
            sys.stderr.write(str(e))

    return n_best_lists
开发者ID:nikkil331,项目名称:Harmonizer,代码行数:35,代码来源:weight_trainer.py

示例2: main

def main():
	parser = argparse.ArgumentParser(description='Decode packets from the Maxkon 433MHz weather station.')
	parser.add_argument('--file', '-f', help='Decode packets from a WAV file')
	parser.add_argument('--show-raw', '-r', action='store_true', help='Show raw packet data in hexidecimal')
	parser.add_argument('--print-on-times', '-t', action='store_true', help='Show the on times as reported by the PWMDecoder')
	args = parser.parse_args()

	decoder = Decoder(args.print_on_times)

	if (args.file):
		# Suppress WAV file warnings
		warnings.filterwarnings('ignore')
		sampFreq, samples = wavfile.read(args.file)
		warnings.filterwarnings('default')

		packets = decoder.add_samples(samples.tolist())
		for packet in packets:
			print_packet(packet, args.show_raw)
	else:
		def audio_samples_ready(samples):
			packets = decoder.add_samples(samples)

			for packet in packets:
				print_packet(packet, args.show_raw)

		audio_in = AudioIn(audio_samples_ready)

		while True:
			time.sleep(0.1)
开发者ID:The6P4C,项目名称:weatherdecode,代码行数:29,代码来源:main.py

示例3: download_file_task

 def download_file_task(self, file_obj, item):
   funcName = "[Downloader.download_file_task]"
   log(6, funcName, 'Downloading file:', file_obj.name)
   decoder = Decoder(item, file_obj)
   try:
     Thread.AcquireLock(self.article_lock)
     for article_obj in file_obj.articles:
       self.article_queue.put(DownloadInfo(file_obj, article_obj, decoder, item))
       log(9, funcName, 'self.article_queue.qsize():', self.article_queue.qsize())
   except:
     log(1, funcName, 'Error adding articles to queue')
   finally:
     Thread.ReleaseLock(self.article_lock)
   log(7, funcName, 'Waiting for decoder to complete for file', file_obj.name)
   decoder.wait()
   log(7, funcName, 'downloaded filename:', decoder.filename, 'size:', len(decoder.data))
   #Core.storage.save(Core.storage.join_path(item.incoming_path, decoder.filename), decoder.data)
   #saver = Saver(item.incoming_path, decoder.filename, decoder.data)
   #saver.save()
   #log(7, funcName, 'saved file:', decoder.filename)
   #return (decoder.filename, decoder.decoded_data)
   if file_obj in item.nzb.rars:
     if item.nzb.rars[item.nzb.rars.index(file_obj)].name != decoder.filename:
       log(3, funcName, 'Updating item nzb rars file to', decoder.filename)
       item.nzb.rars[item.nzb.rars.index(file_obj)].name=decoder.filename
   if file_obj in item.nzb.pars:
     if item.nzb.pars[item.nzb.pars.index(file_obj)].name != decoder.filename:
       log(3, funcName, 'Updating item nzb pars file to', decoder.filename)
       item.nzb.pars[item.nzb.pars.index(file_obj)].name=decoder.filename
     
   item.save()
   return decoder.filename, decoder.data
开发者ID:aamkTV,项目名称:Newsworthy.bundle,代码行数:32,代码来源:downloader.py

示例4: main

def main():
    dbc = DBController()
    dec = Decoder([TLEDecoder(), TLEListDecoder()])

    dlc = None

    try:
        dlc = Downloader()
    except DownloaderError as e:
        print("failed to initialize downloader: " + str(e))
        sys.exit(1)

    for esat in dlc.get_data():
        sats = []
        try:
            sats = dec.decode(esat.fmt, esat.data)
        except DecoderError as e:
            print("failed to decode: " + str(e))

        try:
            for sat in sats:
                dbc.add(sat)
            dbc.sync()
        except DBError as e:
            print("failed to insert into db: " + str(e))
开发者ID:korolevdev,项目名称:SoftwareDesign,代码行数:25,代码来源:main_sat.py

示例5: parse_contents

 def parse_contents(f, bytes_to_read):
   '''
   Do complex reading of caption data from binary file.
   Return a list of statements and characters
   '''
   if DEBUG:
     print 'going to read {bytes} bytes in binary file caption statement.'.format(bytes=bytes_to_read)
   statements = []
   bytes_read = 0
   #TODO: Check to see if decoder state is carred between packet processing
   #currently recreating the decoder (and therefore resetting its state)
   #on every packet paylod processing. This may be incorrect
   decoder = Decoder()
   line = ''
   while bytes_read<bytes_to_read:
     statement = decoder.decode(f)
     if statement:
         bytes_read += len(statement)
         statements.append(statement)
     #if isinstance(statement, code_set.Kanji) or isinstance(statement, code_set.Alphanumeric) \
     #  or isinstance(statement, code_set.Hiragana) or isinstance(statement, code_set.Katakana):
     #  if DEBUG:
     #    print statement #just dump to stdout for now
   #    line += str(statement)
   #if len(line)>0:
   #  print '{l}\n'.format(l=line)
   return statements
开发者ID:Miliox,项目名称:arib,代码行数:27,代码来源:closed_caption.py

示例6: decode

 def decode(self):
     encoded_content = open(self.args.input, 'rb').read()
     mappings = json.loads(open(self.args.mappings, 'r').read())
     decoder = Decoder(encoded_content, mappings)
     raw_content = decoder.decode()
     with open(self.args.output, 'w') as f:
         f.write(raw_content)
开发者ID:JustLiveKZ,项目名称:huffman-coding-src,代码行数:7,代码来源:application.py

示例7: JsonUnmarshaler

class JsonUnmarshaler(object):
    """The top-level Unmarshaler used by the Reader for JSON payloads.  While
    you may use this directly, it is strongly discouraged.
    """
    def __init__(self):
        self.decoder = Decoder()

    def load(self, stream):
        return self.decoder.decode(json.load(stream, object_pairs_hook=OrderedDict))

    def loadeach(self, stream):
        for o in sosjson.items(stream, object_pairs_hook=OrderedDict):
            yield self.decoder.decode(o)
开发者ID:andreypopp,项目名称:transit-python,代码行数:13,代码来源:reader.py

示例8: MsgPackUnmarshaler

class MsgPackUnmarshaler(object):
    """The top-level Unmarshaler used by the Reader for MsgPack payloads.
    While you may use this directly, it is strongly discouraged.
    """
    def __init__(self):
        self.decoder = Decoder()
        self.unpacker = msgpack.Unpacker(object_pairs_hook=OrderedDict)

    def load(self, stream):
        return self.decoder.decode(msgpack.load(stream, object_pairs_hook=OrderedDict))

    def loadeach(self, stream):
        for o in self.unpacker:
            yield self.decoder.decode(o)
开发者ID:andreypopp,项目名称:transit-python,代码行数:14,代码来源:reader.py

示例9: build

 def build(self):
     Window.size = (1024, 520)
     self.dec = Decoder(self.prop_set)
     Clock.schedule_interval(self.update_time, .5)
     Clock.schedule_interval(self.visualize, .4)
     thr = threading.Thread(target=self.get_candata)
     thr.setDaemon(True)
     thr.start()
开发者ID:devova,项目名称:citrocan,代码行数:8,代码来源:main.py

示例10: ric_decode

def ric_decode(imgbuf):
    offset = 0
    boxType = None
    boxLen, boxType, payload = iso_media.read_box(imgbuf[offset:])
    if boxType != "FTYP" or payload != "RIC ":
        print >> sys.stderr, "Fishy file type!!!", boxType, payload
        return None
    offset += boxLen
    boxLen, boxType, payload = iso_media.read_box(imgbuf[offset:])
    if boxType != "ILOT":
        print >> sys.stderr, "No offset table???", boxType
        return None
    offset += boxLen
    layers = wrapper.unwrapLayers(imgbuf[offset:])
    outputImg = Decoder().decode(layers)
    output = StringIO()
    outputImg.save(output, "JPEG", quality = 90);
    return output.getvalue()
开发者ID:kamalendugarai,项目名称:Responsive-Image-Container,代码行数:18,代码来源:ric_encoder.py

示例11: __init__

 def __init__(self, fname):
     self.fname = fname
     self.decoder = Decoder(self)
     self.breakpoints = {}
     self.breakpoint_conditions = {}
     self.prev_input = None
     self.hex_input_mode = False
     self.tracked_registers = set([SP])
     self.reset()
开发者ID:int3,项目名称:uctf-msp430-tools,代码行数:9,代码来源:emulator.py

示例12: decode

    def decode(self, reader, writer):
        '''
        compute pseudo likelihoods the testing set

        Args:
            reader: a feature reader object to read features to decode
            writer: a writer object to write likelihoods
        '''

        #create a decoder
        decoder = Decoder(self.dnn, self.input_dim, reader.max_input_length)

        #read the prior
        prior = np.load(self.conf['savedir'] + '/prior.npy')

        #start tensorflow session
        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True #pylint: disable=E1101
        with tf.Session(graph=decoder.graph, config=config):

            #load the model
            decoder.restore(self.conf['savedir'] + '/final')

            #feed the utterances one by one to the neural net
            while True:
                utt_id, utt_mat, looped = reader.get_utt()

                if looped:
                    break

                #compute predictions
                output = decoder(utt_mat)

                #get state likelihoods by dividing by the prior
                output = output/prior

                #floor the values to avoid problems with log
                np.where(output == 0, np.finfo(float).eps, output)

                #write the pseudo-likelihoods in kaldi feature format
                writer.write_next_utt(utt_id, np.log(output))

        #close the writer
        writer.close()
开发者ID:vrenkens,项目名称:tfkaldi,代码行数:44,代码来源:nnet.py

示例13: run

def run(file_name):
    decoder = Decoder('{}.png'.format(file_name))

    pixel_lines = [
        create_pixels(decoder.Pixel, scanline, decoder.bytes_per_pixel)
        for scanline in decoder.decode()
    ]

    c = Classifier()
    color_lines = []
    for line in pixel_lines:
        colors = [
            c.classify(Point(pixel.red, pixel.green, pixel.blue, pixel.alpha))
            for pixel in line
        ]

        color_lines.append(colors)

    with open('{}_colors.json'.format(file_name), 'w') as file:
        file.write(json.dumps(color_lines))
开发者ID:adregan,项目名称:pnger,代码行数:20,代码来源:make_a_book.py

示例14: decodeAndSolve

def decodeAndSolve(image, showSolution=False):
    d = Decoder(image)
    d.decode()
    s = SuDoKu(d.puzzle)
    solution = s.solution()
    if showSolution:
        img = copy(d.puzzleImage)
        img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
        for q, p in ((x, y) for x in (i * 100 + 30 for i in range(9)) for y in (i * 100 + 70 for i in range(9))):
            if ((q - 30) / 100, (p - 70) / 100) not in d.numberLocations:
                cv2.putText(
                    img,
                    str(solution[(q - 30) / 100][(p - 70) / 100]),
                    (q, p),
                    cv2.FONT_HERSHEY_PLAIN,
                    4,
                    (0, 150, 0),
                    thickness=6,
                )
        cv2.imshow("Solution - Press any key to exit.", img)
        cv2.waitKey(0)
开发者ID:prigarimalla,项目名称:SeeDoKu,代码行数:21,代码来源:seedoku.py

示例15: simulate

    def simulate(self, mode=Decoder.SUM_PROD):
        """

        :param mode: The algorithm (sum-prod vs max-prod) to use in the decoder simulations
        :return:
        """
        self.mode = mode
        self.codewords = []
        self.decoded = []
        for var in self.variance_levels:
            codewords = []
            decoded = []
            transmissions = []
            decoder = Decoder(var, self.mode)
            for i in range(0, self.iterations):
                code = codeword.Codeword()
                codewords.append(code.codeword)
                decoded.append(decoder.decode(code.transmit(var)))
                transmissions.append(code.transmission)
            self.codewords.append(codewords)
            self.decoded.append(decoded)
            self.transmissions.append(transmissions)
开发者ID:finnergizer,项目名称:hamming-decoder-factor-graph,代码行数:22,代码来源:simulator.py


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