-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问ctc_2019中input_length=16, label_length=4的具体使用方法? #46
Comments
我也有这个疑惑,看其他地方都没有用到啊 |
数据生成器和 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 的地方用到了:
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) |
请问一下这边的input_length是啥 |
input_length,代表序列长度,我们这里是4 |
请问序列长度input_length选择16的原因是什么呢,最后一张特征图宽度16有什么关系呢?16是这里的最大取值吗,小一点有什么缺点与优点呢,请赐教 |
input_length 表示 y_pred 的长度,也就是 RNN 输出的序列长度,它和 CNN 输出的宽度是相等的,不能随意修改。 |
|
它和 CNN 输出的宽度是相等的,不能随意修改。不理解CNN输出的宽度指的是什么? |
我已经完成原版keras的使用,但ctc版本有所不同,关于生成器参数多出来两个,请问这两个参数的具体用途是?请问这两个参数该如何理解?
The text was updated successfully, but these errors were encountered: