python - 如何在keras中协调图像和矩阵输入?
问题描述
我想在 Keras 中创建一个模型,该模型从带有n
图像的目录和形状为n rows X m features
.
我知道如何从目录创建生成器以及如何将矩阵数据输入到模型中,但我想使用不同的网络,然后使用merge
它们。
如何确保 then-th image
和 then-th row
在同一步骤中进给?当使用批次时,这些坐标也是如此。
解决方案
它们作为相同的样本喂食,不用担心。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/
推荐阅读
- unity3d - Unity C#:从游戏对象(3D)到画布(屏幕空间 - 相机)的线渲染器
- sql - 如何在 Oracle 中分隔连接的字符串?
- f# - 面向铁路的编程和部分应用
- python - cronicle的插件有哪些参数以及如何添加?
- python - 列表中的 Python 用户输入
- java - 如何在java android中操作数组值
- r - 在 gtable 图中强制等边距
- mysql - 与直接选择相比,查询返回的条件之间没有日期的行更少
- ios - UISwitch 崩溃时的 iOS 触觉反馈
- spring-boot - 从这样的主题获取消息,但只想要短信而不是所有信息,我使用了 jms 监听器和 spring boot