python - 同时使用图像和数字输入的神经网络

标签 python tensorflow keras neural-network conv-neural-network

为了对图像进行分类,我们使用了一个带有几个卷积层和几个全连接层的神经网络。

元数据包含一些有助于对图像进行分类的数字信息。有没有一种简单的方法可以将数字元数据与卷积的输出一起输入到第一个全连接层?是否可以使用 TensorFlow 或更好的 Keras 来实现?

最佳答案

您可以在另一个分支中处理数值数据,然后将结果与 CNN 分支合并,然后将合并后的张量传递给几个最终的密集层。这是解决方案的一般草图:

# process image data using conv layers
inp_img = Input(shape=...)
# ...

# process numerical data
inp_num = Input(shape=...)
x = Dense(...)(inp_num)
out_num = Dense(...)(x)

# merge the result with a merge layer such as concatenation
merged = concatenate([out_conv, out_num])
# the rest of the network ...

out = Dense(num_classes, activation='softmax')(...)

# create the model
model = Model([inp_img, inp_num], out)

当然,要构建这样的模型,您需要使用 Keras Functional API。因此,我强烈建议阅读 official guide为此目的。

关于python - 同时使用图像和数字输入的神经网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53980894/

相关文章:

python - 使用变量时如何修改类

python - 在图像锐化中进行相同操作后得到不同的图像阵列

python - 我在 google colab 上训练了一个 keras 模型。现在无法将其加载到我的系统本地。

python - lxml解析html :wrong result, 为什么

python - 让我们使用 DNS 上的首选挑战来加密手动证书

python - 错误 :tensorflow:Couldn't match files for checkpoint

docker - Windows中拒绝docker权限

arrays - tflite 对象检测推理无法正常工作

Python:model.fit() 错误,不支持 None 值

python - 具有多个输出的 LSTM 时间序列预测