python - 使用 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"])
解决方案
推荐阅读
- asp.net-core - 使用 nswagger studio 在 .net Core 中获取 Iactionresult 的结果
- go - go tool dist: FAILED: not a Git repo; 必须在 $GOROOT 中放置一个 VERSION 文件
- numpy - Numpy 高级索引:广播是如何发生的?
- javascript - 反应原生导航5慢渲染?
- javascript - 如何告诉本地节点模块所需的 dll 存储在哪里?
- vue.js - vue js中文本区域的单向绑定-安全使用`:value`?
- powershell - Powershell设置内容替换字符串
- python - 如何在 MacOS 中从 Python 运行 Stata do 文件
- django - Django DB 设计 - 使用 unique_together 预订特定的唯一 URL
- node.js - 在nodejs rest api中得到404