首页 > 解决方案 > 如何在keras中协调图像和矩阵输入?

问题描述

我想在 Keras 中创建一个模型,该模型从带有n图像的目录和形状为n rows X m features.

我知道如何从目录创建生成器以及如何将矩阵数据输入到模型中,但我想使用不同的网络,然后使用merge它们。

如何确保 then-th image和 then-th row在同一步骤中进给?当使用批次时,这些坐标也是如此。

标签: pythonkeras

解决方案


它们作为相同样本喂食,不用担心。Keras 将要求您n在第一维中拥有两个输入张量,因此,没有什么可以出错的。确保images.shape[0] == matrix.shape[0]. 这是唯一的条件,它将授予来自两个输入的并行样本。

imageInput = Input((side1,side2,channels))   
matrixInput = Input((m,))

#use these two inputs in a model here
.....
#merge the two sides somehow

outputTensorFromTheLastLayer = #get this from your last layer in the model

#instantiate the model with 2 inputs
model = Model([imageInput,matrixInput], outputTensorFromTheLastLayer)

至于合并有很多可能性,你必须有创意。

注意您尝试合并的张量的形状并使用一些可能的合并层:https ://keras.io/layers/merge/


推荐阅读