简体   繁体   English

多 Output 卷积神经网络

[英]Multi Output Convolutional Neural Network

I am developing a convolutional neural network for image classification or better for classification of license plates.我正在开发一个用于图像分类的卷积神经网络,或者更好地用于车牌分类。 These license plates contain up to 8 characters and for each character 37 characters are possible (AZ, 0-9 and a blank space).这些车牌最多包含 8 个字符,每个字符可以包含 37 个字符(AZ、0-9 和一个空格)。 I am now wondering how to design the two last layers in my network.我现在想知道如何设计网络中的最后两层。 I think, the last one has to be a softmax layer with 37 probabilities.我认为,最后一个必须是具有 37 个概率的 softmax 层。 This should be fully connected to one(?) neuron in the layer before?这应该完全连接到之前层中的一个(?)神经元? I think, in the layer before we need 8 neurons because of the 8 characters in the license plate before but I am not sure here.我认为,在之前的层中我们需要 8 个神经元,因为之前的车牌中有 8 个字符,但我在这里不确定。 Before this layers I add some convolutional and maxPooling layers.在这些层之前,我添加了一些卷积层和 maxPooling 层。 Is that a valid approach or do you have other suggestions?这是一种有效的方法还是您有其他建议?

I wrote this code:我写了这段代码:

from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), input_shape = (600, 1200, 1), activation = "relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(64, activation = "relu"))
model.add(Dense(8, activation = "relu"))
model.add(Dense(37, activation = "softmax"))

model.compile(optimizer="rmsprop", loss="categorical_crossentropy", metrics=["accuracy"])

Especially regarding the layers after my Flatten Layer I am really unsure... Is there someone who can help?尤其是关于我的 Flatten Layer 之后的层,我真的不确定......有没有人可以帮忙? I hope I described my problem properly...我希望我正确地描述了我的问题......

On your previous layers, there are many commonly used architectures which you could try to obtain better accuracy on your dataset.在您之前的层中,有许多常用的架构,您可以尝试在数据集上获得更好的准确性。

On the dense layers, there are multiple ways you could tackle it.在密集层上,有多种方法可以解决它。 Since, there are atmost 8 characters with 37 possible characters each.因为,最多有 8 个字符,每个字符有 37 个可能的字符。 You could have the last layer as model.add(Dense(37*8, activation = "sigmoid")) with thresholding at 0.5 to denote all the 37*8 possibilities.您可以将最后一层设置为model.add(Dense(37*8, activation = "sigmoid")) ,阈值为 0.5 以表示所有 37*8 的可能性。

 model = Sequential()
 model.add(Conv2D(32, kernel_size=(3, 3), input_shape = (600, 1200, 1), activation = "relu"))
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Dropout(0.25))
 model.add(Flatten())
 model.add(Dense(64, activation = "relu"))
 model.add(Dense(37*8, activation = "relu"))

A more apt way could be having 9 output layers: one with 8 neurons to denote the the presence of a character and other 8 layers with 37 neurons each with softmax to denote what character it is.更合适的方法可能是使用 9 个 output 层:一个有 8 个神经元来表示字符的存在,另外 8 层有 37 个神经元,每个都有 softmax 来表示它是什么字符。 Note that to do this you must use Functional API instead of Sequential API.请注意,要执行此操作,您必须使用功能 API 而不是顺序 API。

An example:一个例子:

 inp = Input(shape=(600,1200,1))
 X = Conv2D(32, kernel_size=(3, 3), activation = "relu")(inp)
 X = MaxPooling2D(pool_size=(2, 2))(X)
 X = Dropout(0.25)(X)
 X = Flatten()(X)
 X = Dense(64, activation = "relu")(X)
 P = Dense(8, activation = "relu")(X)
 C1 = Dense(37, activation = "softmax")(X)
 ...
 C8 = Dense(37, activation = "softmax")(X)
 model = Model(inp, [P,C1,C2,...C8])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM