Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

训练集和测试结果类别不一致 #3433

Closed
1 task done
fengyuan106 opened this issue Aug 4, 2023 · 5 comments
Closed
1 task done

训练集和测试结果类别不一致 #3433

fengyuan106 opened this issue Aug 4, 2023 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@fengyuan106
Copy link

问题确认 Search before asking

  • 我已经搜索过问题,但是没有找到解答。I have searched the question and found no related answer.

请提出你的问题 Please ask your question

您好,我在训练集中一共有11个类别,训练好模型后进行测试时,发现类别除了011外,还有类别12,13,14,15,多了4个类别,不知道是什么原因造成的?类别011分割都很准确,类别12~15发现是一些零星的边缘线

@fengyuan106 fengyuan106 added the question Further information is requested label Aug 4, 2023
@Asthestarsfalll
Copy link
Contributor

是不是模型的num_classes参数没有改

@fengyuan106
Copy link
Author

在配置文件.yml文件中,已经改了,num_classes = 12, 0代表背景,1~11是各个物体

@Asthestarsfalll
Copy link
Contributor

请给出配置文件内容、训练命令、测试命令

@fengyuan106
Copy link
Author

fengyuan106 commented Aug 9, 2023

配置文件:
batch_size: 2
iters: 8000

train_dataset:
type: Dataset
dataset_root: data/mydata
train_path: data/mydata/train_list.txt
num_classes: 12
transforms:
- type: Resize
target_size: [1080, 720]
- type: RandomHorizontalFlip
- type: Normalize
mode: train

val_dataset:
type: Dataset
dataset_root: data/mydata
val_path: data/mydata/val_list.txt
num_classes: 12
transforms:
- type: Resize
target_size: [1080, 720]
- type: Normalize
mode: val

optimizer:
type: SGD
momentum: 0.9
weight_decay: 4.0e-5

lr_scheduler:
type: PolynomialDecay
learning_rate: 0.01
end_lr: 0
power: 0.9

loss:
types:
- type: CrossEntropyLoss
coef: [1]

model:
type: DeepLabV3P
backbone:
type: ResNet50_vd
output_stride: 8
multi_grid: [1, 2, 4]
pretrained: https://bj.bcebos.com/paddleseg/dygraph/resnet50_vd_ssld_v2.tar.gz
num_classes: 12
backbone_indices: [0, 3]
aspp_ratios: [1, 12, 24, 36]
aspp_out_channels: 256
align_corners: False
pretrained: null

训练命令:
python tools/train.py --config configs/quick_start/my.yml --save_interval 500 --do_eval --use_vdl --save_dir output

测试命令:
python tools/predict.py --config configs/quick_start/my.yml --model_path output/best_model/model.pdparams --image_path E:/Semantics_Blender/Image_cat --save_dir output/result

@fengyuan106
Copy link
Author

找到问题了,我修改了tools/predict.py中的写入方式,我希望得到原始的预测结果(变量pred),我将未经处理的pred写为图像,格式为.jpg时出现了上述问题,换成.png就好了。

代码如下

my

        from PIL import Image
        raw_image = Image.fromarray(pred)
        raw_image_path = os.path.join(
            raw_saved_dir, os.path.splitext(im_file)[0] + ".png")
        mkdir(raw_image_path)
        raw_image.save(raw_image_path)

感谢您的解答!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants