例如,我想训练一个神经网络来预测图片的位置(经度、纬度),并将图像、温度、湿度和一年中的时间作为模型的输入。
我的问题是,将此附加信息添加到 cnn 的最佳方法是什么?我应该在最后一个密集层或开头将数字输入与 cnn 合并吗?我应该对数值(温度、湿度和一年中的时间)进行编码吗?
任何信息、资源和来源将不胜感激,在此先感谢。
最佳答案
您可以单独处理数字输入,然后在进行最终预测之前合并它们:
# Your usual CNN whatever it may be
img_in = Input(shape=(width, height, channels))
img_features = SomeCNN(...)(img_in)
# Your usual MLP model
aux_in = Input(shape=(3,))
aux_features = Dense(24, activation='relu')(aux_in)
# Possibly add more hidden layers, then merge
merged = concatenate([img_features, aux_features])
# create last layer.
out = Dense(num_locations, activation='softmax')(merged)
# build model
model = Model([img_in, aux_in], out)
model.compile(loss='categorical_crossentropy', ...)
从本质上讲,您将它们视为单独的输入,并学习有用的特征,这些特征结合起来可以让您的模型进行预测。如何对数字输入进行编码实际上取决于它们的类型。
对于像温度这样的连续输入,您可以在 -1, 1
之间归一化,对于离散输入,one-hot 是很常见的。这是一个快速 guide .
关于python - keras 神经网络中的多种输入类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50556812/