简体   繁体   English

ValueError:检查输入时出错:预期 input_1 有 5 个维度,但得到形状为 (1221, 50, 50, 1) 的数组

[英]ValueError: Error when checking input: expected input_1 to have 5 dimensions, but got array with shape (1221, 50, 50, 1)

Im trying to run a model with xtrain=(1221,50,50,1) at the time of model.fit its showing this error我试图在模型时使用xtrain=(1221,50,50,1)运行模型。 model.fit它显示此错误

ValueError: Error when checking input: expected input_1 to have 5 dimensions, but got array with shape (1221, 50, 50, 1) ValueError:检查输入时出错:预期 input_1 有 5 个维度,但得到形状为 (1221, 50, 50, 1) 的数组

im using these functions:我正在使用这些功能:

model.compile(loss=categorical_crossentropy,optimizer=Adadelta(lr=0.8), metrics=['acc'])
model.fit(x=ZZ, y=yyy, batch_size=128, epochs=1, validation_split=0.2)

when i increase the dimensions to (1221,50,50,1,1) using expand_dims im getting this error:当我使用 expand_dims 将尺寸增加到 (1221,50,50,1,1) 时,我收到此错误:

ValueError: Error when checking input: expected input_1 to have shape (16, 50, 50, 1) but got array with shape (1221,50, 50, 1, 1) ValueError:检查输入时出错:预期 input_1 具有形状 (16, 50, 50, 1) 但得到形状为 (1221,50, 50, 1, 1) 的数组

Idk where im getting wrong我知道我哪里出错了

this is my model这是我的模型

input_layer = Input((16, 50, 50, 1))
## convolutional layers
conv_layer1 = Conv3D(filters=8, kernel_size=(3, 3, 3), activation='relu')(input_layer)
conv_layer2 = Conv3D(filters=16, kernel_size=(3, 3, 3), activation='relu')(conv_layer1)

## add max pooling to obtain the most imformatic features
pooling_layer1 = MaxPool3D(pool_size=(2, 2, 2))(conv_layer2)

conv_layer3 = Conv3D(filters=32, kernel_size=(3, 3, 3), activation='relu')(pooling_layer1)
conv_layer4 = Conv3D(filters=64, kernel_size=(3, 3, 3), activation='relu')(conv_layer3)
pooling_layer2 = MaxPool3D(pool_size=(2, 2, 2))(conv_layer4)

## perform batch normalization on the convolution outputs before feeding it to MLP architecture
pooling_layer2 = BatchNormalization()(pooling_layer2)
flatten_layer = Flatten()(pooling_layer2)

## create an MLP architecture with dense layers : 4096 -> 512 -> 10
## add dropouts to avoid overfitting / perform regularization
dense_layer1 = Dense(units=2048, activation='relu')(flatten_layer)
dense_layer1 = Dropout(0.4)(dense_layer1)
dense_layer2 = Dense(units=512, activation='relu')(dense_layer1)
dense_layer2 = Dropout(0.4)(dense_layer2)
output_layer = Dense(units=6, activation='softmax')(dense_layer2) #Use 5 instead of 1

## define the model with input layer and output layer
model = Model(inputs=input_layer, outputs=output_layer)```
input_layer = Input((16, 50, 50, 1))

This line specify that an input has a shape of (16, 50, 50 ,1) .此行指定输入的形状为(16, 50, 50 ,1) You're passing to the network the whole (1221, 50, 50, 1) vector.您将整个(1221, 50, 50, 1)向量传递给网络。 You need to reshape to (X, 16, 50, 50, 1) so that an element of the vector has the shape desired (16, 50, 50, 1) .您需要重塑为(X, 16, 50, 50, 1)以便向量的元素具有所需的形状(16, 50, 50, 1)

The problem is in your xtrain , it consists 1221 images of shape (50,50,1) however, the Conv3D is expecting images of shape (16,50,50,1) .问题出在您的xtrain ,它包含 1221 张形状为 (50,50,1) 的图像,但是,Conv3D 需要形状为(16,50,50,1)图像。

In case you are confused, the input_layer to Conv2D doesn't require the total number of images value.如果您感到困惑, input_layer的 input_layer 不需要图像总数值。 It only requires the shape of the image coming to it.它只需要图像的形状。

For your help, you can look at this example how the images are being passed and set.为了您的帮助,您可以查看示例如何传递和设置图像。

I get what mistake I did my x_train should have consist of (X,16,50,50,1) but the 16 was not there.我知道我犯了什么错误,我的 x_train 应该由 (X,16,50,50,1) 组成,但 16 不在那里。 this is due to an error in which the input was taken.这是由于输入错误造成的。

Thank you for your help Rishabh Sahrawat Orphee Faucoz MH304感谢您的帮助 Rishabh Sahrawat Orphee Faucoz MH304

暂无
暂无

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

相关问题 ValueError:检查输入时出错:预期 input_1 具有形状 (50,),但使用 ELMo 嵌入和 LSTM 获得形状为 (1,) 的数组 - ValueError: Error when checking input: expected input_1 to have shape (50,) but got array with shape (1,) with ELMo embeddings and LSTM ValueError:检查输入时出错:预期lstm_1_input具有3个维,但数组的形状为(393613,50) - ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (393613, 50) ValueError:检查输入时出错:预期 input_1 有 4 个维度,但得到了形状为(无、无、无)的数组 - ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (None, None, None) ValueError:检查输入时出错:期望input_1有4个维度,但得到的数组有形状(6243,256,256) - ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (6243, 256, 256) ValueError:检查输入时出错:预期 input_1 有 5 个维度,但得到了形状为 (10000, 32, 3, 32) 的数组 - ValueError: Error when checking input: expected input_1 to have 5 dimensions, but got array with shape (10000, 32, 3, 32) Keras LSTM输入-ValueError:检查输入时出错:预期input_1具有3维,但数组的形状为(1745,1) - Keras LSTM Input - ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (1745, 1) 检查输入时出错:预期dense_1_input 有2 维,但得到了形状为(25000, 700, 50) 的数组 - Error when checking input: expected dense_1_input to have 2 dimensions, but got array with shape (25000, 700, 50) ValueError:检查输入时出错:预期 input_1 的形状为 (168, 5),但数组的形状为 (5808, 5) - ValueError: Error when checking input: expected input_1 to have shape (168, 5) but got array with shape (5808, 5) 检查输入时出错:预期conv2d_6_input具有4个维度,但数组的形状为(270,50,50) - Error when checking input: expected conv2d_6_input to have 4 dimensions, but got array with shape (270, 50, 50) 如何修复“检查输入时出错:预期 input_1 有 2 个维度,但得到的数组形状为 (32, 168, 5)” - How to fix 'Error when checking input: expected input_1 to have 2 dimensions, but got array with shape (32, 168, 5)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM