准确率为0的CNN Python Keras问题

我正在处理一个二元分类问题。起初准确率为69%,但由于内存不足,我缩小了一些参数,现在准确率变为0。你们知道这是怎么回事吗?

model = Sequential()from keras.layers import Dropoutmodel.add(Conv2D(96, kernel_size=11, padding="same", input_shape=(300, 300, 1), activation = 'relu'))model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))model.add(Conv2D(128, kernel_size=3, padding="same", activation = 'relu'))model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))model.add(Conv2D(128, kernel_size=3, padding="same", activation = 'relu'))model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))from keras.layers.core import Activationmodel.add(Flatten())# model.add(Dense(units=1000, activation='relu'  ))model.add(Dense(units= 300, activation='relu'))model.add(Dropout(0.2))model.add(Dense(1))model.add(Activation("softmax"))model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])from keras.preprocessing.image import ImageDataGeneratordatagen = ImageDataGenerator(    featurewise_center=True,    rotation_range=90,    fill_mode='nearest',    validation_split = 0.2    )datagen.fit(train)train_generator = datagen.flow(train, train_labels, batch_size=8)# # fits the model on batches with real-time data augmentation:history = model.fit_generator(generator=train_generator,                    use_multiprocessing=True,                    steps_per_epoch = len(train_generator) / 8,                    epochs = 5,                    workers=20)

回答:

Softmax函数只应在多类分类问题中使用。你从Dense层只有一个输出,因此应该使用sigmoid函数。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注