用于识别序列数据的CNN模型的配置 - CNN顶层的架构 - Parallel Layers [英] Configuration of CNN model for recognition of sequential data - Architecture of the top of the CNN - Parallel Layers

查看:38
本文介绍了用于识别序列数据的CNN模型的配置 - CNN顶层的架构 - Parallel Layers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置一个网络来识别车牌等序列数据的字符.现在我想在深度自动车牌识别系统中使用表 3 中提到的架构(链接:

第一层很常见,但我绊倒的地方是架构的顶部(红框中的部分).他们提到了 11 个并行层,我真的不确定如何在 Python 中获得它.我编写了这个架构,但对我来说似乎不合适.

model = Sequential()model.add(Conv2D(64, kernel_size=(5, 5), input_shape = (32, 96, 3), activation = "relu"))model.add(MaxPooling2D(pool_size=(2, 2)))模型.添加(辍学(0.25))model.add(Conv2D(128, kernel_size=(3, 3), activation = "relu"))model.add(MaxPooling2D(pool_size=(2, 2)))模型.添加(辍学(0.25))model.add(Conv2D(256, kernel_size=(3, 3), activation = "relu"))model.add(MaxPooling2D(pool_size=(2, 2)))模型.添加(辍学(0.25))模型.添加(展平())模型.添加(密集(1024,激活=relu"))模型.添加(密集(11 * 37,激活=Softmax"))model.add(keras.layers.Reshape((11, 37)))

有人可以帮忙吗?我必须如何编写顶部代码才能获得与作者相同的架构?

解决方案

下面的代码可以构建图中描述的架构.

将tensorflow导入为tf从 tensorflow.keras.models 导入顺序,模型从 tensorflow.keras.layers 导入 Conv2D、Flatten、MaxPooling2D、Dense、Input、Reshape、Concatenate、Dropoutdef create_model(input_shape = (32, 96, 1)):input_img = 输入(形状=输入形状)'''在此处添加 ST 层.'''模型 = Conv2D(64, kernel_size=(5, 5), input_shape = input_shape, activation = "relu")(input_img)模型 = MaxPooling2D(pool_size=(2, 2))(model)模型 = Dropout(0.25)(模型)模型 = Conv2D(128, kernel_size=(3, 3), input_shape = input_shape, activation = "relu")(model)模型 = MaxPooling2D(pool_size=(2, 2))(model)模型 = Dropout(0.25)(模型)模型 = Conv2D(256, kernel_size=(3, 3), input_shape = input_shape, activation = "relu")(model)模型 = MaxPooling2D(pool_size=(2, 2))(model)模型 = Dropout(0.25)(模型)模型 = 展平()(模型)骨干=密集(1024,激活=relu")(模型)分支 = []对于范围内的 i (11):分支.附加(主干)branch[i] = Dense(37, activation = "softmax", name="branch_"+str(i))(branches[i])输出 = 连接(轴 = 1)(分支)输出 = 重塑((11, 37))(输出)模型 = 模型(输入图像,输出)回报模式

I am trying to configure a network for character recognition of sequential data like license plates. Now I would like to use the architecture which is noted in Table 3 in Deep Automatic Licence Plate Recognition system (link: http://www.ee.iisc.ac.in/people/faculty/soma.biswas/Papers/jain_icgvip2016_alpr.pdf).

The architecture the authors presented is this one:

The first layers are very common, but where I was stumbling was the top (the part in the red frame) of the architecture. They mention 11 parallel layers and I am really unsure how to get this in Python. I coded this architecture but it does not seem to be right to me.

model = Sequential()
model.add(Conv2D(64, kernel_size=(5, 5), input_shape = (32, 96, 3), activation = "relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(128, kernel_size=(3, 3), activation = "relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(256, kernel_size=(3, 3), activation = "relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(1024, activation = "relu"))
model.add(Dense(11*37, activation="Softmax"))
model.add(keras.layers.Reshape((11, 37)))

Could someone help? How do I have to code the top to get an equal architecture like the authors?

解决方案

The code below can build the architecture described in the image.

import tensorflow as tf
from tensorflow.keras.models import Sequential, Model
from tensorflow.keras.layers import Conv2D, Flatten, MaxPooling2D, Dense, Input, Reshape, Concatenate, Dropout

def create_model(input_shape = (32, 96, 1)):
    input_img = Input(shape=input_shape)
    '''
    Add the ST Layer here.
    '''
    model = Conv2D(64, kernel_size=(5, 5), input_shape = input_shape, activation = "relu")(input_img)
    model = MaxPooling2D(pool_size=(2, 2))(model)
    model = Dropout(0.25)(model)

    model = Conv2D(128, kernel_size=(3, 3), input_shape = input_shape, activation = "relu")(model)
    model = MaxPooling2D(pool_size=(2, 2))(model)
    model = Dropout(0.25)(model)

    model = Conv2D(256, kernel_size=(3, 3), input_shape = input_shape, activation = "relu")(model)
    model = MaxPooling2D(pool_size=(2, 2))(model)
    model = Dropout(0.25)(model)

    model = Flatten()(model)
    backbone = Dense(1024, activation="relu")(model)

    branches = []
    for i in range(11):
        branches.append(backbone)
        branches[i] = Dense(37, activation = "softmax", name="branch_"+str(i))(branches[i])
    
    output = Concatenate(axis=1)(branches)
    output = Reshape((11, 37))(output)
    model = Model(input_img, output)

    return model

这篇关于用于识别序列数据的CNN模型的配置 - CNN顶层的架构 - Parallel Layers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆