【问题标题】:Keras - Image to Word (OCR)Keras - 图像到文字 (OCR)
【发布时间】:2017-08-10 06:44:49
【问题描述】:

我正在尝试构建一个非常简单的 OCR 来开始我在更大模型上的测试。这里的问题是我无法弄清楚我的训练输出数据应该如何

代码:

def simple_model():

    output = 28

    if K.image_data_format() == 'channels_first':
        input_shape = (1, input_height, input_width)
    else:
        input_shape = (input_height, input_width, 1)

    conv_to_rnn_dims = (input_width // (2), (input_height // (2)) * conv_blades)

    model = Sequential()
    model.add(Conv2D(conv_blades, (3, 3), input_shape=input_shape, padding='same'))
    model.add(MaxPooling2D(pool_size=(2,2), name='max2'))
    model.add(Reshape(target_shape=conv_to_rnn_dims, name='reshape'))
    model.add(GRU(64, return_sequences=True, kernel_initializer='he_normal', name='gru1'))
    model.add(TimeDistributed(Dense(output, kernel_initializer='he_normal', name='dense2')))
    model.add(Activation('softmax', name='softmax'))

    model.compile(loss='mse',
                optimizer='adamax',
                metrics=["accuracy"])

    return model

img = load_img('exit.png', grayscale=True, target_size=[input_height,     input_width])  
x = img_to_array(img)  
x = x.reshape((1,) + x.shape)  

y = np.array(['exit'])

model = simple_model()

model.fit(x, y, batch_size=1,
                    epochs=10,
                    validation_data=(x, y),
                    verbose=1)

print model.predict(y)

图片示例:


(来源:exitfest.org

当我运行此代码时,我收到以下错误:

ValueError: Error when checking target: expected softmax to have 3 dimensions, but got array with shape (1, 1)

注意 1:我知道我不能只用一个图像和一个标签来训练我的模型,我知道我还有很多这样的图像,但首先我需要运行这个简单的模型,然后再改进它。

注意2:这是我第一次使用Image-to-Sequence输出,可能还有其他问题,如果有这种错误,请随时更改代码。

【问题讨论】:

  • 进入模型的输入形状听起来有点问题。
  • 好的,应该怎么样?
  • 对不起,这只是一个假设,还不知道应该如何,因为我正在处理这个话题
  • 花了一些时间试图弄清楚如何适应 softmax 激活,但现在没有运气。但是有一个示例 github.com/fchollet/keras/blob/master/examples/image_ocr.py 与您想要做的非常相似。
  • keras/examples上的例子最后用的是CTC,我想建一个不用CTC的神经网络,因为我看不懂。我在一些论文中看到它提高了精确度和召回率,但我认为现在不是我使用它的时候。

标签: image-processing neural-network nlp deep-learning keras


【解决方案1】:

好吧,由于我没有收到任何答案,我将链接到答案I posted in another question

这里我解释一下如何使用 keras OCR 示例并回答一些其他问题。

【讨论】:

    猜你喜欢
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多