使用图像和数字输入的神经网络

Mic*_*lli 4 python neural-network conv-neural-network keras tensorflow

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

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

tod*_*day 5

您可以在另一个分支中处理数值数据,然后将结果与 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)
Run Code Online (Sandbox Code Playgroud)

当然,要构建这样的模型,您需要使用 Keras 功能 API。因此,我强烈建议您阅读官方指南