Python数组重塑问题到具有形状的数组(无,192)

时间:2016-10-19 22:54:26

标签: python numpy keras

我有这个错误,我不知道如何重塑None的维度。

Exception: Error when checking : expected input_1 to have shape (None, 192) but got array with shape (192, 1)

如何将数组重塑为(None,192)?

我的数组accuracy的形状为(12, 16),我的accuracy.reshape(-1)提供了(192,)。但这不是(None, 192)

1 个答案:

答案 0 :(得分:0)

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)进行比较,并跳过第一轴;这是比较1921。如果array的形状为(n, 192),它可能会通过。

所以基本上,生成(192,1)形状的东西,而不是(1,192)或可广播的(192,)导致错误。

我在猜测这是问题模块的标签上添加keras

搜索其他keras标记的SO问题:

Exception: Error when checking model target: expected dense_3 to have shape (None, 1000) but got array with shape (32, 2)

Error: Error when checking model input: expected dense_input_6 to have shape (None, 784) but got array with shape (784L, 1L)

Dimensions not matching in keras LSTM model

Getting shape dimension errors with a simple regression using Keras

Deep autoencoder in Keras converting one dimension to another i

我不太了解keras以了解答案,但除了重塑输入数组之外,还有更多内容。