这些图像的“噪声”是否太大,以至于无法被CNN正确分类?

我正在尝试构建一个图像分类器,用于识别房产网站上的两种类型的图像。我的数据集被分为两类:[房产,房间]。我希望能够区分图像是房产的外部还是房产内部的房间。

下面是两种类型的图像示例。我的数据集包含每个类别800张图像,并为每个类别额外准备了160张图像作为训练集(不在测试集中)。

我在训练过程中总是能得到不错的结果,但在用一些真实样本测试时,通常会将所有图像分类到单一类别中。

您可以看到我使用的模型如下:

train_datagen = ImageDataGenerator(    rescale=1./255,    width_shift_range=0.1,    height_shift_range=0.1,    rotation_range=10,    shear_range=0.2,    zoom_range=0.2,    horizontal_flip=True,    fill_mode='nearest') # set validation splitvalidate_datagen = ImageDataGenerator(rescale=1./255)IMG_HEIGHT = IMG_WIDTH = 128model = tf.keras.models.Sequential([    tf.keras.layers.Conv2D(32, (11,11), activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH, 3), padding='same'),    tf.keras.layers.MaxPooling2D(11, 11),    # tf.keras.layers.Dropout(0.5),    # Second convolutional layer    tf.keras.layers.Conv2D(64, (11, 11), padding='same', activation='relu'),    tf.keras.layers.MaxPooling2D(11, 11),    # tf.keras.layers.Dropout(0.5),    # Flattening    tf.keras.layers.Flatten(),    # Full connection    tf.keras.layers.Dense(128, activation='relu'),    tf.keras.layers.Dropout(0.5),    tf.keras.layers.Dense(1, activation='sigmoid')])from tensorflow.keras.optimizers import RMSpropmodel.compile(    optimizer=RMSprop(lr=0.001),    loss='binary_crossentropy',    metrics=['accuracy'])# now train the modelhistory = model.fit_generator(    train_generator,    validation_data=validation_generator,    steps_per_epoch=75, #100    epochs=5, # 15, or 20, and 100 steps per epoch    validation_steps=50,    verbose=1)# Predict imagedef load_image(img_path, show=False):  test_image = image.load_img(img_path, target_size=(IMG_HEIGHT, IMG_WIDTH))  test_image = image.img_to_array(test_image)  test_image /= 255.  test_image = np.expand_dims(test_image, axis = 0)  return test_imagedef predict_image(img_path, show=False):  loaded_img = load_image(img_path, show)  pred = model.predict(loaded_img)  return 'property' if pred[0][0] == 0.0 else 'room'print('Prediction is...')print(predict_image('path/to/my/img')

谁能建议一下可能的原因?我已经尝试了不同的epochs和batch大小,进一步增强了图像,改变了Conv2D和Pooling层的尺寸,但似乎都没有帮助。

我是否数据不够,或者这些图像一开始就不好?这是我第一次涉足机器学习,如果我的问题看起来很明显,请原谅我。

enter image description here

enter image description here

enter image description here

enter image description here


回答:

您没有正确地对分类器的输出进行后处理,它输出的概率在[0, 1]之间,值 < 0.5对应第一个类别,值 >= 0.5对应第二个类别。您应该相应地更改代码。

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中创建了一个多类分类项目。该项目可以对…

发表回复

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