我正试图用猫和狗的图像来训练CNN。代码如下:
model = Sequential()
model.add(Reshape((32, 32, 3)))
model.add(Conv2D(32, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Conv2D(32, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Conv2D(32, (3, 3), padding = 'same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dense(2))
model.add(Activation('softmax'))
opt = keras.optimizers.legacy.RMSprop(learning_rate=0.0001, decay=1e-6)
model.compile(loss='categorical_crossentropy',
optimizer=opt,
metrics=['accuracy'])
history = model.fit(cd_train_inputs.shape, cd_train_labels.shape,
validation_data=(cd_test_inputs.shape, cd_test_labels.shape), \
epochs=70)
print(model.summary())
字符串
当我运行上面的代码时,我得到以下错误:
ValueError: Data cardinality is ambiguous:
x sizes: 4
y sizes: 1
Make sure all arrays contain the same number of samples.
型
我怎么才能让它工作?
1条答案
按热度按时间i7uq4tfw1#
当调用
model.fit()
时,你希望传递底层的X和y数据,而不是Tensor的形状:字符串