问题描述
我有此错误,我不确定如何使用None
重整尺寸.
I have this error and I'm not sure how do I reshape where there's a dimension with None
.
Exception: Error when checking : expected input_1 to have shape (None, 192) but got array with shape (192, 1)
如何将数组重塑为(None,192)?
How do I reshape an array to (None, 192)?
我有形状为(12, 16)
的数组accuracy
,我做了给出了(192,)
的accuracy.reshape(-1)
.但这不是(None, 192)
.
I've the array accuracy
with shape (12, 16)
and I did accuracy.reshape(-1)
that gives (192,)
. However this is not (None, 192)
.
推荐答案
在keras/keras/engine/training.py
def standardize_input_data(data, names, shapes=None,
check_batch_dim=True,
exception_prefix=''):
...
# check shapes compatibility
if shapes:
for i in range(len(names)):
...
for j, (dim, ref_dim) in enumerate(zip(array.shape, shapes[i])):
if not j and not check_batch_dim:
# skip the first axis
continue
if ref_dim:
if ref_dim != dim:
raise Exception('Error when checking ' + exception_prefix +
': expected ' + names[i] +
' to have shape ' + str(shapes[i]) +
' but got array with shape ' +
str(array.shape))
将其与错误进行比较
Error when checking : expected input_1 to have shape (None, 192) but got array with shape (192, 1)
因此,它正在将(None, 192)
与(192, 1)
进行比较,并跳过第一个轴.就是比较192
和1
.如果array
具有形状(n, 192)
,则它可能会通过.
So it is comparing (None, 192)
with (192, 1)
, and skipping the 1st axis; that is comparing 192
and 1
. If array
has shape (n, 192)
it probably would pass.
因此,基本上,与(1,192)
或可广播的(192,)
相反,生成(192,1)
形状的原因都是导致错误的原因.
So basically, what ever is generating the (192,1)
shape, as opposed to (1,192)
or a broadcastable (192,)
is causing the error.
我要在标签上添加keras
,因为这是问题模块.
I'm adding keras
to the tags on the guess that this is the problem module.
搜索其他带有keras
标签的SO问题:
Searching other keras
tagged SO questions:
异常:错误在检查模型目标时:预期density_3具有形状(无,1000),但具有形状(32,2)的数组
错误:检查模型输入时出错:预期density_input_6具有形状(None,784),但具有形状为(784L,1L)的数组
使用以下方法通过简单回归获得形状尺寸误差凯拉斯(Keras)
我对keras
的了解不多,无法理解答案,但是它不仅仅是重塑输入数组而已.
I don't know enough about keras
to understand the answers, but there's more to it than simply reshaping your input array.
这篇关于Python数组整形问题到具有形状的数组(无,192)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!