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

问题描述 投票:0回答:2

我正在尝试使用xtrain=(1221,50,50,1)运行模型在model.fit时显示此错误

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

使用这些功能的即时消息:

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)

当我将尺寸增加到(1221,50,50,1,1)时使用expand_dims即时通讯收到此错误:

[ValueError:检查输入时出错:预期输入_1具有形状(16、50、50、1),但具有形状为(1221、50、50、1、1)的数组]

Idk即时通讯出现问题

这是我的模特

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)```

我正在尝试在模型生成时使用xtrain =(1221,50,50,1)运行模型。显示其此错误ValueError:检查输入时出错:预期input_1具有5个维度,但数组包含。 ..

python opencv tensorflow keras deep-learning
2个回答
0
投票
input_layer = Input((16, 50, 50, 1))

0
投票

问题出在xtrain中,它包含1221个形状为(50,50,1)的图像,但是Conv3D期望使用形状为(16,50,50,1)的图像。

© www.soinside.com 2019 - 2024. All rights reserved.