我刚开始机器学习,我正在制作一个数据集,里面有海洋、森林、冰川、街道、建筑物和山脉的14k张图片(6级)。我一直在用它训练我的模型,达到了91%的val acc,但出于某种原因,它是有偏见的,当我试图用我的推理代码预测新的图像时,唯一选择的类别是冰川和海洋。下面是带有模型创建代码和推理代码的Github。
train_datagen = ImageDataGenerator(
rotation_range= 20, # Rotate the augmented image by 20 degrees
zoom_range=0.3, # Zoom by 20% more or less
horizontal_flip=True, # Allow for horizontal flips of augmented images
vertical_flip=True, # Allow for vertical flips of augmented images
brightness_range=[0.6, 1.2], # Lighter and darker images
fill_mode='nearest',
preprocessing_function=preprocess_input)
img_data_iterator = train_datagen.flow_from_directory(
# Where to take the data from, the classes are the sub folder names
'../Q2B/archive/seg_train/seg_train/',
class_mode="categorical", # classes are in 2D one hot encoded way
shuffle=True, # shuffle the data, default is true but just to point it out
batch_size=32,
target_size=(150, 150), # This size is the default of mobilenet NN)
validation_generator = ImageDataGenerator(
preprocessing_function=preprocess_input).flow_from_directory(
'../Q2B/archive/seg_test/seg_test/',
class_mode="categorical",
shuffle=True,
batch_size=32,
target_size=(150, 150),)我的猜测是,这与我预处理数据的方式有关。
发布于 2022-05-29 13:43:24
你能张贴更多的你的代码。将火车和测试生成器的class_mode更改为“分类”,将最终的密集层从1更改为2,因此这将返回两个类的分数/概率。因此,当您使用argmax时,它将返回得分最高的索引位置,指示它预测的类别。
https://stackoverflow.com/questions/72424042
复制相似问题