1 Star 0 Fork 0

587/captcha_trainer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
decoder.py 819 Bytes
一键复制 编辑 原始数据 按行查看 历史
kerlomz 提交于 2019-11-30 16:10 +08:00 . 加了一些注释
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Author: kerlomz <kerlomz@gmail.com>
import tensorflow as tf
from config import ModelConfig
class Decoder:
"""
转录层:用于解码预测结果
"""
def __init__(self, model_conf: ModelConfig):
self.model_conf = model_conf
self.category_num = self.model_conf.category_num
def ctc(self, inputs, sequence_length):
"""针对CTC Loss的解码"""
ctc_decode, _ = tf.nn.ctc_greedy_decoder(inputs, sequence_length)
decoded_sequences = tf.sparse.to_dense(ctc_decode[0], default_value=self.category_num, name='dense_decoded')
return decoded_sequences
@staticmethod
def cross_entropy(inputs):
"""针对CrossEntropy Loss的解码"""
return tf.argmax(inputs, 2, name='dense_decoded')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wpj/captcha_trainer.git
git@gitee.com:wpj/captcha_trainer.git
wpj
captcha_trainer
captcha_trainer
master

搜索帮助