首页 > 解决方案 > 使用 CNN 从图像中识别文本

问题描述

我如何实现这个 CNN 模型来从图像中识别文本,我将非常感谢任何帮助,因为我在生成训练集和测试集时遇到了一个大问题。

img = layers.Input(shape=img_shape) # Get image as an input and process it through some Convs
conv1 = layers.Conv2D(16, (3, 3), padding='same', activation='relu')(img)
mp1 = layers.MaxPooling2D(padding='same')(conv1)
conv2 = layers.Conv2D(32, (3, 3), padding='same', activation='relu')(mp1)
mp2 = layers.MaxPooling2D(padding='same')(conv2)
conv3 = layers.Conv2D(32, (3, 3), padding='same', activation='relu')(mp2)
bn = layers.BatchNormalization()(conv3)
mp3 = layers.MaxPooling2D(padding='same')(bn) 

# Get flattened vector and make 5 branches from it. Each branch will predict one letter
flat = layers.Flatten()(mp3)
outs = []
for _ in range(5):
    dens1 = layers.Dense(64, activation='relu')(flat)
    drop = layers.Dropout(0.5)(dens1)
    res = layers.Dense(num_symbols, activation='sigmoid')(drop)

    outs.append(res)

# Compile model and return it
model = Model(img, outs)
model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=["accuracy"])

标签: pythontensorflowconv-neural-networktext-recognition

解决方案


推荐阅读