简体   繁体   English

作为 Keras 模型输入的列表列表

[英]List of lists as Input to a Keras Model

I'm trying to implement a model for which the input should be a list of lists:我正在尝试实现一个模型,其输入应该是列表列表:

inputs = [ [np.array([...]), ..., np.array([...])], [np.array([...]), ..., np.array([...])] ]

I can not convert the inner lists in two np array since the shapes of them don't allow that.我无法转换两个 np 数组中的内部列表,因为它们的形状不允许这样做。

When I pass the inputs to the model I receive the following error:当我将输入传递给模型时,我收到以下错误:

Please provide as model inputs either a single array or a list of arrays.

How can I feed my inputs to the model?如何将我的输入提供给模型? Thanks谢谢

You must have compatible shapes, that's unavoidable.你必须有兼容的形状,这是不可避免的。

The only case that accepts list of lists if when you have model with "more than one input tensor".如果您的模型具有“多个输入张量”,则唯一接受列表列表的情况。

The solutions for you are:为您提供的解决方案是:

  • Padding the data: add a padding so every array has the same shape填充数据:添加填充使每个数组都具有相同的形状
  • Train separate arrays, one at a time, using train_on_batch instead of fit in a manual training loop.使用train_on_batch而不是适合手动训练循环,一次训练一个单独的数组。 Each of the separate arrays must have a well defined shape.每个单独的阵列都必须具有明确定义的形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM