输入形状为[?,1,148,32]的'max_pooling2d_3 / MaxPool'(op:'MaxPool')从1中减去2导致的负尺寸大小

时间:2018-10-16 10:18:07

标签: python tensorflow keras

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(32, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(64, (3, 3),padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Flatten())  # this converts our 3D feature maps to 1D feature 
vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
    #sgd = optimizers.SGD(lr=0.0001, decay=1e-6, momentum=0.9)


model.compile(loss='sparse_categorical_crossentropy',  
`optimizer=Adam(lr=0.001), # Adam optimizer with 1.0e-4 learning rate
metrics = ['accuracy']) # Metrics to be evaluated by the model

当我编译以上代码时,出现此错误 输入形状为[?,1,75,32]的'max_pooling2d_8 / MaxPool'(op:'MaxPool')从1中减去2导致的负尺寸大小。

我尝试使用相同的填充,但仍然无法正常工作

1 个答案:

答案 0 :(得分:2)

非常确定是否要更改

model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))

model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3),padding='same'))

(您可能还需要更改数据的形状)

它将按预期工作。