我有一个数据集,看起来像:
emotion images
0 0 [[70, 80, 82, 72, 58, 58, 60, 63, 54, 58, 60, ...
1 0 [[151, 150, 147, 155, 148, 133, 111, 140, 170,...
2 2 [[231, 212, 156, 164, 174, 138, 161, 173, 182,...
3 4 [[24, 32, 36, 30, 32, 23, 19, 20, 30, 41, 21, ...
4 6 [[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 15, 2...
情感列是一个分类变量,图像包含表示图像的numpy数组(size=(48,48))。
我的任务是图像分类,我使用的是keras。
当我尝试:
model.fit(df['images'], df['emotion'], epochs= 10, batch_size = 32)
我得到一个值错误:
值错误:检查输入时出错:预期的conv2d_1_输入具有
4维,但得到带形状的数组(28708,1)
我明白
fit()
需要numpy对象,我已尝试按建议使用“df.values”
here
. 但这对我来说不太管用。
我想预处理的方式,也批量与大小32我的输入我不知道如何从这里预处理或重塑我的数据,以便我可以在我的网络上训练它与凯拉斯。
如何将数据更改为网络预期的4维?
model.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_7 (Conv2D) (None, 46, 46, 64) 640
_________________________________________________________________
activation_7 (Activation) (None, 46, 46, 64) 0
_________________________________________________________________
conv2d_8 (Conv2D) (None, 44, 44, 32) 18464
_________________________________________________________________
activation_8 (Activation) (None, 44, 44, 32) 0
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 22, 22, 32) 0
_________________________________________________________________
conv2d_9 (Conv2D) (None, 20, 20, 32) 9248
_________________________________________________________________
activation_9 (Activation) (None, 20, 20, 32) 0
_________________________________________________________________
conv2d_10 (Conv2D) (None, 18, 18, 32) 9248
_________________________________________________________________
activation_10 (Activation) (None, 18, 18, 32) 0
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 9, 9, 32) 0
_________________________________________________________________
conv2d_11 (Conv2D) (None, 7, 7, 32) 9248
_________________________________________________________________
activation_11 (Activation) (None, 7, 7, 32) 0
_________________________________________________________________
conv2d_12 (Conv2D) (None, 5, 5, 32) 9248
_________________________________________________________________
activation_12 (Activation) (None, 5, 5, 32) 0
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 2, 2, 32) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 128) 0
_________________________________________________________________
dense_1 (Dense) (None, 128) 16512
_________________________________________________________________
activation_13 (Activation) (None, 128) 0
_________________________________________________________________
dense_2 (Dense) (None, 7) 903
_________________________________________________________________
activation_14 (Activation) (None, 7) 0
=================================================================
Total params: 73,511
Trainable params: 73,511
Non-trainable params: 0
我的型号代码:
model = Sequential()
model.add(Conv2D(64, (3,3), input_shape = (48, 48, 1)))
model.add(Activation('relu'))
model.add(Conv2D(32, (3,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(32, (3,3)))
model.add(Activation('relu'))
model.add(Conv2D(32, (3,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(32, (3,3)))
model.add(Activation('relu'))
model.add(Conv2D(32, (3,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D (pool_size = (2, 2)))
model.add(Flatten())
model.add(Dense(units = 128))
model.add(Activation('relu'))
model.add(Dense(units= 7))
model.add(Activation('softmax'))
model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
编辑:如果你对这个问题投了反对票,请告诉我为什么不应该出现堆栈溢出,或者这类问题有什么问题会用它作为我以后的帖子的反馈。