我正在尝试构建一个可在 3D 体素网格上工作的卷积网络。我尝试添加全连接层但收到错误:
ValueError:检查目标时出错:预期dense_1具有2维,但得到形状为(68,50,50,50,1)的数组
当我首先有一个展平层时,怎么会发生这种情况?我当时对致密层的输入不应该是平坦的吗?
x, y = load_data(directory)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=42)
model = Sequential()
model.add(Convolution3D(1, kernel_size=(3, 3, 3), activation='relu',
border_mode='same', name='conv1',
input_shape=(50, 50, 50, 1)))
model.add(MaxPooling3D(pool_size=(2, 2, 2)))
model.add(Flatten())
model.add(Dense(32))
model.compile(
loss='mean_squared_error',
optimizer='adam',
metrics=['accuracy']
)
model.fit(
x_train,
y_train,
epochs=10,
batch_size=32,
)
model.evaluate(x_test, y_test)
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1 (Conv3D) (None, 50, 50, 50, 1) 28
_________________________________________________________________
max_pooling3d_1 (MaxPooling3 (None, 25, 25, 25, 1) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 15625) 0
_________________________________________________________________
dense_1 (Dense) (None, 32) 500032
=================================================================