为了对图像进行分类,我们使用了一个带有几个卷积层和几个全连接层的神经网络。
元数据包含一些有助于对图像进行分类的数字信息。有没有一种简单的方法可以将数字元数据与卷积的输出一起输入到第一个全连接层?是否可以使用 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/