Comments (8)
我也有这个疑惑,看其他地方都没有用到啊
from captcha_break.
数据生成器和 CNN 的差不多,这里需要多几个矩阵,一个是 input_length,代表序列长度,一个是 label_length,代表验证码长度,还有一个 np.ones,没有意义,只是为了适配 Keras 训练需要的矩阵输入。
from tensorflow.keras.utils import Sequence
class CaptchaSequence(Sequence):
def __init__(self, characters, batch_size, steps, n_len=4, width=128, height=64,
input_length=16, label_length=4):
self.characters = characters
self.batch_size = batch_size
self.steps = steps
self.n_len = n_len
self.width = width
self.height = height
self.input_length = input_length
self.label_length = label_length
self.n_class = len(characters)
self.generator = ImageCaptcha(width=width, height=height)
def __len__(self):
return self.steps
def __getitem__(self, idx):
X = np.zeros((self.batch_size, self.height, self.width, 3), dtype=np.float32)
y = np.zeros((self.batch_size, self.n_len), dtype=np.uint8)
input_length = np.ones(self.batch_size)*self.input_length
label_length = np.ones(self.batch_size)*self.label_length
for i in range(self.batch_size):
random_str = ''.join([random.choice(self.characters) for j in range(self.n_len)])
X[i] = np.array(self.generator.generate_image(random_str)) / 255.0
y[i] = [self.characters.find(x) for x in random_str]
return [X, y, input_length, label_length], np.ones(self.batch_size)
input_length 和 label_length 都在计算 loss 的地方用到了:
y_pred
是模型的输出,是按顺序输出的37个字符的概率,因为我们这里用到了循环神经网络,所以需要一个空白字符的概念;labels
是验证码,是四个数字,每个数字代表字符在字符集里的位置input_length
表示y_pred
的长度,我们这里是16label_length
表示labels
的长度,我们这里是4
import tensorflow.keras.backend as K
def ctc_lambda_func(args):
y_pred, labels, input_length, label_length = args
return K.ctc_batch_cost(labels, y_pred, input_length, label_length)
from captcha_break.
请问一下这边的input_length是啥
from captcha_break.
请问一下这边的input_length是啥
input_length,代表序列长度,我们这里是4
from captcha_break.
请问序列长度input_length选择16的原因是什么呢,最后一张特征图宽度16有什么关系呢?16是这里的最大取值吗,小一点有什么缺点与优点呢,请赐教
from captcha_break.
请问序列长度input_length选择16的原因是什么呢,最后一张特征图宽度16有什么关系呢?16是这里的最大取值吗,小一点有什么缺点与优点呢,请赐教
input_length 表示 y_pred 的长度,也就是 RNN 输出的序列长度,它和 CNN 输出的宽度是相等的,不能随意修改。
from captcha_break.
请问序列长度input_length选择16的原因是什么呢,最后一张特征图宽度16有什么关系呢?16是这里的最大取值吗,小一点有什么缺点与优点呢,请赐教
input_length 表示 y_pred 的长度,也就是 RNN 输出的序列长度,它和 CNN 输出的宽度是相等的,不能随意修改。谢谢
from captcha_break.
请问序列长度input_length选择16的原因是什么呢,最后一张特征图宽度16有什么关系呢?16是这里的最大取值吗,小一点有什么缺点与优点呢,请赐教
input_length 表示 y_pred 的长度,也就是 RNN 输出的序列长度,它和 CNN 输出的宽度是相等的,不能随意修改。谢谢
它和 CNN 输出的宽度是相等的,不能随意修改。不理解CNN输出的宽度指的是什么?
from captcha_break.
Related Issues (20)
- 如何把保存下来的ctc模型载入继续训练呢?
- 您可否告知下这几个文件是独立运行的吗,如何训练自己的中文验证码呢 HOT 5
- RNN分类之后, 在评估处怎么获得每个字符的概率呢 HOT 1
- 楼主您好,请问3500常用汉字的验证码识别,该模型大小够吗? HOT 5
- 多行验证码如何识别呢? HOT 4
- loss为负数且不断减小
- cannot import name '_imaging' from 'PIL'
- 变长标签怎么处理
- 如果验证码最后两位相同,似乎一定识别错误 HOT 4
- 运行winpy/main.py遇到的问题 HOT 5
- train和val的acc都可以到99%,但是eval,只有0.00265,这是怎么回事呢
- 尝试把n_class+1程序可以运行,但是不知道对不对 HOT 1
- 请问如果是不定长的验证码 可以使用吗 HOT 2
- 使用CTC, 识别时不限制4个字符长度,识别率如何? HOT 3
- CTC模型不定长输出问题 HOT 1
- 效果不理想
- 训练完了怎么用啊,纯小白 HOT 2
- cnn_2019.ipynb(防止 tensorflow 占用所有显存)tensorflow2.0要怎么改 HOT 1
- tensorflow 2.0 训练的时候 日志不显示 不知道 训练到哪一步 HOT 1
- 请问我改如何替换掉ctc_2019中的lambda方法呢 因为lambda在加载保存的模型会有错误 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from captcha_break.