首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像分类器仅预测6类中的2级,且val精度较高,发生了什么?

图像分类器仅预测6类中的2级,且val精度较高,发生了什么?
EN

Stack Overflow用户
提问于 2022-05-29 13:26:27
回答 1查看 22关注 0票数 0

我刚开始机器学习,我正在制作一个数据集,里面有海洋、森林、冰川、街道、建筑物和山脉的14k张图片(6级)。我一直在用它训练我的模型,达到了91%的val acc,但出于某种原因,它是有偏见的,当我试图用我的推理代码预测新的图像时,唯一选择的类别是冰川和海洋。下面是带有模型创建代码和推理代码的Github

代码语言:javascript
复制
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),)

我的猜测是,这与我预处理数据的方式有关。

EN

回答 1

Stack Overflow用户

发布于 2022-05-29 13:43:24

你能张贴更多的你的代码。将火车和测试生成器的class_mode更改为“分类”,将最终的密集层从1更改为2,因此这将返回两个类的分数/概率。因此,当您使用argmax时,它将返回得分最高的索引位置,指示它预测的类别。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72424042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档