本文介绍了向卷积神经网络输入添加附加值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要输入到卷积神经网络模型的图像数据集,但是,对于这些图像中的每一个,距与图像关联的对象都有一定的距离或距离.

I have a dataset of images I want to input to a Convolutional Neural Network Model, however, with each of these images, there is a range or distance from the object associated with the image.

我想输入此范围作为CNN模型的附加上下文.

I want to input this range as an additional piece of context for the CNN model.

提供这些额外的信息是否有好处?这样做有意义吗?在Keras可行吗?

Does providing this extra piece of information provide any benefit? Does it make sense to do? Is it feasible in Keras?

谢谢!

推荐答案

您在这里有几个选择,一个是将数值编码为输入中的特征平面.如果您的数值为c,则可以向每个输入图像添加一个通道,每个像素的值均为c.

You have a few options here, one is to encode your numerical value as a feature plane in your input. If your numerical value is c you can add a channel to each input image with the value c at every pixel.

另一种选择是将值合并为完全连接层的附加输入.

Another option is to merge the value in as an additional input to the fully connected layer.

在喀拉拉邦,这看起来像:

In keras this would look something like:

conv = Sequential()
conv.add(Conv2D(32, kernel_size=(3, 3), strides=(1, 1),
                 activation='relu',
                 input_shape=input_shape))
conv.add(MaxPooling2D(pool_size=(2, 2)))
conv.add(Flatten())
conv.add(Dense(512, activation='relu'))

range = Sequential()
range.add(Dense(1, input_shape=(1,), activation='relu'))

merged = Concatenate([conv, range])
merged.add(Dense(n_classes, activation='softmax'))

merged.compile(optimizer='adam', loss='binary_crossentropy',
           metrics=['accuracy'])

您选择哪个选项取决于您的数据,以及您是否认为数字功能将有助于卷积层更好地理解输入,还是您认为以后不需要它.如果有时间,您可以尝试两种架构,看看哪种架构效果更好.

Which option you choose will depend on your data and whether you think the numerical feature will help the convolutional layers better understand the input, or whether you think it's not needed until later. If you have time you can try both architectures and see which performs better.

这篇关于向卷积神经网络输入添加附加值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 02:51