Adding an additional value to a Convolutional Neural Network Input? [closed]

喜夏-厌秋 提交于 2020-02-01 05:20:06

问题


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.

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

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

Thanks!


回答1:


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.



来源:https://stackoverflow.com/questions/47818968/adding-an-additional-value-to-a-convolutional-neural-network-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!