tensorflow - 将多维 NumPy 数组与列表传递给 fit() 会引发错误
问题描述
我正在试验 w/conv 层。我想输入两个 192x192x3 的图像,将它们连接起来,然后做一些其他的事情。模型摘要如下所示:
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_40 (InputLayer) (None, 192, 192, 3) 0
__________________________________________________________________________________________________
input_41 (InputLayer) (None, 192, 192, 3) 0
__________________________________________________________________________________________________
concatenate_7 (Concatenate) (None, 192, 192, 6) 0 input_40[0][0]
input_41[0][0]
我的shape
两个输入看起来像这样:(1, 192, 192, 3)
如果我将 a 传递list()
给该fit()
方法,它可以正常工作,即:model.fit([input1, input2], ...)
它可以正常工作。但是,如果我首先转换为 NumPy 数组:np_array = np.asarray([input1, input2])
形状(2, 1, 192, 192, 3)
为该fit()
方法时会出现此错误:
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[[[[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
...,
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]],
[[1., 1., 1.],
[1.,...
有任何想法吗?
解决方案
将数据传递给多个输入时,它应该是数组列表而不是一个大数组。有什么理由需要将它作为数组传递吗?
推荐阅读
- jpa - 如何将 PSQL ::json @> ::json 转换为 jpa/jpql-predicate
- angular - The best way to handle environments in Angular with Typescript
- javascript - Passing Variables from one page to another
- tensorflow - 如何解决 Trainable-False 在 Keras 中不起作用的问题?
- google-sheets - 如何翻译 ARRAYFORMULA 中的 QUERY 公式以自动填充每行的 QUERY
- php - 如何使用 NGINX 在 docker 中设置动态子域
- c# - Unable to run SAS script through C#
- javascript - Vue 将子组件的方法暴露给父组件
- python - 如何通过遵循相邻标准快速收集点列表
- typescript - Angular not displaying data from component.ts to html