简体   繁体   English

ValueError:检查目标时出错:预期density_1具有2维,但数组的形状为(68,50,50,50,1)

[英]ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (68, 50, 50, 50, 1)

I'm trying to build a convolutional network that will work on a 3D voxel grid. 我正在尝试建立一个可在3D体素网格上工作的卷积网络。 I try to add a fully connected layer but get an error: 我尝试添加一个完全连接的层,但出现错误:

ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (68, 50, 50, 50, 1) ValueError:检查目标时出错:预期density_1具有2维,但数组的形状为(68,50,50,50,1)

How can this be happening when I have a flatten layer first? 当我首先有一个平坦的层时,这怎么可能发生? Shouldn't my input to the dense layer at that point be, well, flat? 那时候我对密集层的输入不应该平坦吗?

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    
=================================================================

train_test_split method split arrays into train and test set. train_test_split方法将数组拆分为训练集和测试集。 If input to the method are list of arrays, the methods returns train and test tuples. 如果该方法的输入是数组列表,则这些方法将返回train和test元组。

train_set, test_set = train_test_split(x, y, test_size=0.25, random_state=42)
x_train, y_train = train_set
x_test, y_test = test_set

or since python support left side assignment to tuples, 或者由于python支持左侧分配给元组,

(x_train, y_train), (x_test, y_test) = train_test_split(x, y, test_size=0.25, random_state=42)

暂无
暂无

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

相关问题 ValueError:检查目标时出错:预期density_2具有4维,但数组的形状为(64,50)(Keras) - ValueError: Error when checking target: expected dense_2 to have 4 dimensions, but got array with shape (64, 50) (Keras) ValueError:检查目标时出错:预期dense_2具有形状(1,)但得到形状为(50,)的数组 - ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (50,) ValueError:检查目标时出错:预期dense_22具有形状(100, 50)但得到形状为(1, 50)的数组 - ValueError: Error when checking target: expected dense_22 to have shape (100, 50) but got array with shape (1, 50) ValueError:检查目标时出错:预期dense_1有2维,但得到了形状为(2849、1、2)的数组 - ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (2849, 1, 2) MobileNet ValueError:检查目标时出错:预期dense_1有4维,但得到形状为(24, 2)的数组 - MobileNet ValueError: Error when checking target: expected dense_1 to have 4 dimensions, but got array with shape (24, 2) 如何修复'ValueError:检查目标时出错:预期density_1具有2维,但数组的形状为(373,2,2) - How to fix 'ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (373, 2, 2)' ValueError:检查目标时出错:预期 activation_10 有 2 个维度,但得到了形状为 (118, 50, 1) 的数组 - ValueError: Error when checking target: expected activation_10 to have 2 dimensions, but got array with shape (118, 50, 1) 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) 检查输入时出错:预期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:检查目标时出错:预期 dense_1 具有形状 (7, 7) 但得到的数组具有形状 (7, 1) - ValueError: Error when checking target: expected dense_1 to have shape (7, 7) but got array with shape (7, 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM