ValueError:检查目标时出错:期望dense_5有4个维度,但得到的数组有形状(3,1)

时间:2018-03-17 06:00:45

标签: python tensorflow keras

I am working in keras tensorflow on Windows 10
I tried a lot but could'nt find the missing dimension .
# Here is a snippet of my code with summary.

{
train_datagen = ImageDataGenerator( preprocessing_function=None)
train_generator = train_datagen.flow_from_directory(
    'human_faces',
    target_size=(250,250),
     batch_size=3,
     class_mode='binary',classes=0)


# input_shape(no. of images/batch_size,height,width,channel(RGB))
model = Sequential()
model.add(Dense(32,batch_size=3, input_shape=(250,250,3)))
model.add(Activation('relu'))
model.add(Dense(10)),
model.add(Activation('softmax'))
model.add(Dropout(0.02))


#layer = Dropout(0.02)

#further layers:
model.add(Dense(units=5)) #hidden layer 1
model.add(Dense(units=4)) #output layer
#model.add(Conv2D(3, (3, 3)))
model.add(Conv2D(3,(3,3),input_shape=
(3,250,250,3),data_format='channels_last'))
model.add(MaxPooling2D(pool_size=(2, 2),input_shape=(3,250,250,3),
                       data_format='channels_last'))
model.add(Dense(4,batch_size=3,input_shape=(124,124,3)))

model.compile(loss=losses.mean_squared_error, optimizer='sgd')

sgd = optimizers.SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)

  test_generator = ImageDataGenerator()

validation_generator = test_generator.flow_from_directory(
    'human_faces/validation',
    target_size=(250,250),
    batch_size=3,
    class_mode=None,classes=0)

model.summary()
model.fit_generator(
        train_generator,
        steps_per_epoch=1,## batch_size,
        #steps_per_epoch=3,
        epochs=5,
        validation_data=validation_generator,
     #  validation_steps=61 )  # batch_size)
        validation_steps=1)  

}

找到了属于4个班级的61张图片。 找到0个图像属于0个类。

图层(类型)输出形状参数#

dense_1(密集)(3,250,250,32)128

activation_1(激活)(3,250,250,32)0

dense_2(密集)(3,250,250,10)330

activation_2(激活)(3,250,250,10)0

dropout_1(辍学)(3,250,250,10)0

dense_3(密集)(3,250,250,5)55

dense_4(密集)(3,250,250,4)24

conv2d_1(Conv2D)(3,248,248,3)111

max_pooling2d_1(MaxPooling2(3,124,124,3)0

dense_5(密集)(3,124,124,4)16

总参数:664 可训练的参数:664 不可训练的参数:0

0 个答案:

没有答案