我有一个 Tensorflow CNN 模型,它接受图像(固定大小)作为输入,输出是 5 个数字(模型的最后一层是具有 5 个神经元的密集层,线性激活)。因此,为了管理数据,我自然有一个电子表格,其中包含训练图像的信息,后跟 5 列数字。现在我正在考虑训练一个单独的模型,该模型以图像 + 4 个数字作为输入,并预测最后一个数字。关于如何做到这一点有什么想法吗?
我已经看过Funtional API 页面以及这个问题。但我不知道如何将图像与数字结合起来。连接似乎不太合适。这 4 个数字应该作为密集神经元出现吗?如果是这样,那么这将发生在 Conv2D 层之后。
欢迎任何建议和参考。
考虑采用集成技术来提高模型性能。使用 CNN 处理图像数据,使用密集网络处理数值数据。将它们的输出合并为一个模型。
你可以使用tensorflow尝试这样的事情
# Define and train CNN for image data
image_model = Sequential([
Conv2D(...),
MaxPooling2D(...),
Flatten(),
Dense(...)
])
image_model.compile(...)
image_model.fit(...)
# Define and train dense networks for numerical data
numerical_model = Sequential([
Dense(...),
Dense(...),
...
])
numerical_model.compile(...)
numerical_model.fit(...)
# Combine models
combined_model = Sequential([
Concatenate([image_model.output, numerical_model.output]),
Dense(...),
...
])
combined_model.compile(...)
combined_model.fit(...)