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

训练自己的数据集问题 #76

Closed
ruoyuchen0903 opened this issue Jun 26, 2022 · 25 comments
Closed

训练自己的数据集问题 #76

ruoyuchen0903 opened this issue Jun 26, 2022 · 25 comments

Comments

@ruoyuchen0903
Copy link

AssertionError: Results do not correspond to current coco set

@mingwz
Copy link

mingwz commented Jun 27, 2022

老哥你解决了吗?我也是遇到了相同的问题

@ExWang
Copy link

ExWang commented Jun 27, 2022

When generate_coco_format_labels, this repo make img_id by osp.basename(img_path).split('.')[0] in datasets.py. You will get str label.

BUT, when evaluating results, this repo make img_id by int(path.stem) if path.stem.isnumeric() else path.stem in convert_to_coco_format in evaler.py. You may get int label.

Then, coco tools will check these img_id, so lead this AssertionError.

So I suggest to modify image_id = int(path.stem) if path.stem.isnumeric() else path.stem to image_id = path.stem to solve this error.

@mingwz
Copy link

mingwz commented Jun 27, 2022

Thanks for your reply! I solve the problem by this way. @ExWang

@ruoyuchen0903
Copy link
Author

ruoyuchen0903 commented Jun 27, 2022 via email

@ExWang
Copy link

ExWang commented Jun 28, 2022

so how can I solve it? 2022-06-27 15:05:30"Nebula Wang" @.>写道: when generate_coco_format_labels, this repo make img_id by osp.basename(img_path).split('.')[0] in datasets.py. You will get 'str' label. BUT, when evaluating results, this repo make img_id by 'int(path.stem) if path.stem.isnumeric() else path.stem'. You may get 'int' label. After, coco tools will check these img_id, so lead this AssertionError — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.>

image

@moxigk
Copy link

moxigk commented Jun 28, 2022

之前的错误是:
TypeError: '<' not supported between instances of 'str' and 'int'

我根据你的方法改了,出现了这个问题
AssertionError: Results do not correspond to current coco set

是不是数据集的名字必须是数字吗?不能包含英文吗或者其他字符吗?

@xiaoluxiaoluxiaolu
Copy link

Hello, I would like to know which file needs to be modified

@ExWang
Copy link

ExWang commented Jun 28, 2022

Hello, I would like to know which file needs to be modified

no file need to be modified now, some one fix it, pull new repo will slove the problem.

@ExWang
Copy link

ExWang commented Jun 28, 2022

之前的错误是: TypeError: '<' not supported between instances of 'str' and 'int'

我根据你的方法改了,出现了这个问题 AssertionError: Results do not correspond to current coco set

是不是数据集的名字必须是数字吗?不能包含英文吗或者其他字符吗?

我看不是必须数字的,最早这个repo生成image_id用的 img_id = osp.basename(img_path).split('.')[0] 是str的id。但是在后面predict的时候,用的 img_id = int(path.stem) if path.stem.isnumeric() else path.stem ,也就是说,假设你的图片名字是数字的,就会转成int的id。这就造成了coco检查img_id的时候,发现他们对不上,引发了这个Error.

不过这个不统一的问题好像在最近的一个commit中修复了,pull一下最新的就行

@nidetaoge
Copy link

Have already pulled the newest commit, but still get the same error:
pred = anno.loadRes(pred_json)
File "/opt/conda/lib/python3.8/site-packages/pycocotools/coco.py", line 341, in loadRes
assert set(annsImgIds) == (set(annsImgIds) & set(self.getImgIds())),
AssertionError: Results do not correspond to current coco set

@Mobu59
Copy link

Mobu59 commented Jun 28, 2022

@nidetaoge have you fixed the problem?

@yutao007
Copy link

将这里的images_id修改后,仍然还是报错。感觉这一块有问题没有完全解决。其中我的环境是:
torch 1.10.0+cu111
torchaudio 0.10.0+rocm4.1
torchvision 0.11.0+cu111

修改处
def save_one_json(predn, jdict, path, class_map):
# Save one JSON result {"image_id": 42, "category_id": 18, "bbox": [258.15, 41.29, 348.26, 243.78], "score": 0.236}
#image_id = int(path.stem) if path.stem.isnumeric() else path.stem
image_id = path.stem

报错处
assert set(annsImgIds) == (set(annsImgIds) & set(self.getImgIds())),
AssertionError: Results do not correspond to current coco set
terminate called without an active exception
Aborted (core dumped)

@qybing
Copy link

qybing commented Jun 28, 2022

1.把datasets.py文件的img_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem
2.把evaler.py文件的image_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem
就可以运行起来了

@Mobu59
Copy link

Mobu59 commented Jun 28, 2022

1.把datasets.py文件的img_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem 2.把evaler.py文件的image_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem 就可以运行起来了

Thanks, I made it

@yutao007
Copy link

谢谢博主解答,我已经按照提示将datasets.py evaler.py val.py 三个文件中关于image_id的赋值都改成了path.stem
但还是报错,如果别人没错的话,那应该就是我这边数据集或者别的问题了
assert set(annsImgIds) == (set(annsImgIds) & set(self.getImgIds())),
AssertionError: Results do not correspond to current coco set

@yutao007
Copy link

问题解决了,要记得删掉先前跑数据生成的json文件。

@luckyeap2020
Copy link

之前的错误是: TypeError: '<' not supported between instances of 'str' and 'int'

我根据你的方法改了,出现了这个问题 AssertionError: Results do not correspond to current coco set

是不是数据集的名字必须是数字吗?不能包含英文吗或者其他字符吗?

不用改源代码,只用一个粗暴的方式解决了:

  1. 数据集中文件的名称只用数字
  2. 删除之前训练产生的所有过程文件,即只保留原始数据集的图片和标注

@ruabliuqiu
Copy link

训练前,自己数据集分布和制作方法跟yolov5一样,不需要json格式标签。我参考这个博主的方法训练成功了,https://blog.csdn.net/DeepLearning_/article/details/125511165?spm=1001.2014.3001.5502

@shenshi19
Copy link

训练前,自己数据集分布和制作方法跟yolov5一样,不需要json格式标签。我参考这个博主的方法训练成功了,https://blog.csdn.net/DeepLearning_/article/details/125511165?spm=1001.2014.3001.5502
兄弟,你的yaml文件是什么样子的,我参考了你发的链接还是有问题的

@Yaomingyang
Copy link

官方已经解决这个问题了,重新下载工程,按照docs/Train_custom_data.md运行即可

@ruabliuqiu
Copy link

训练前,自己数据集分布和制作方法跟yolov5一样,不需要json格式标签。我参考这个博主的方法训练成功了,https://blog.csdn.net/DeepLearning_/article/details/125511165?spm=1001.2014.3001.5502
兄弟,你的yaml文件是什么样子的,我参考了你发的链接还是有问题的

yaml中只保留train和val,去掉test和anno_path

@yaos666
Copy link

yaos666 commented Jun 30, 2022

1.把datasets.py文件的img_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem 2.把evaler.py文件的image_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem 就可以运行起来了

成功啦,必须把datasets.py、evaler.py都改了才能运行起来,只改evaler.py文件还是会报错的哟

@shenshi19
Copy link

1.把datasets.py文件的img_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem 2.把evaler.py文件的image_id = int(path.stem) if path.stem.isnumeric() else path.stem改成img_id = path.stem 就可以运行起来了

成功啦,必须把datasets.py、evaler.py都改了才能运行起来,只改evaler.py文件还是会报错的哟

新版的好像datasets.py好像img_id-int()那里改了

@suzauddola
Copy link

Evaluating mAP by pycocotools.
Saving runs/train/ttop_6s_3004/predictions.json...
ERROR in evaluate and save model.
ERROR in training loop or eval/save model.

Training completed in 0.039 hours.
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
Loading and preparing results...
Traceback (most recent call last):
File "tools/train.py", line 94, in
main(args)
File "tools/train.py", line 84, in main
trainer.train()
File "/YOLOv6/yolov6/core/engine.py", line 70, in train
self.train_in_loop()
File "/YOLOv6/yolov6/core/engine.py", line 89, in train_in_loop
self.eval_and_save()
File "/YOLOv6/yolov6/core/engine.py", line 115, in eval_and_save
self.eval_model()
File "/YOLOv6/yolov6/core/engine.py", line 134, in eval_model
results = eval.run(self.data_dict,
File "/yolov6/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/YOLOv6/tools/eval.py", line 83, in run
eval_result = val.eval_model(pred_result, model, dataloader, task)
File "/YOLOv6/yolov6/core/evaler.py", line 127, in eval_model
pred = anno.loadRes(pred_json)
File "/home/suza/.conda/envs/yolov6/lib/python3.8/site-packages/pycocotools/coco.py", line 327, in loadRes
assert set(annsImgIds) == (set(annsImgIds) & set(self.getImgIds())),
AssertionError: Results do not correspond to current coco set

When generate_coco_format_labels, this repo make img_id by osp.basename(img_path).split('.')[0] in datasets.py. You will get str label.

BUT, when evaluating results, this repo make img_id by int(path.stem) if path.stem.isnumeric() else path.stem in convert_to_coco_format in evaler.py. You may get int label.

Then, coco tools will check these img_id, so lead this AssertionError.

So I suggest to modify image_id = int(path.stem) if path.stem.isnumeric() else path.stem to image_id = path.stem to solve this error.

After changing to "image_id = path.stem" now this error appears !!

@jcrdeep
Copy link

jcrdeep commented Jul 4, 2022

#207 (comment)

This resolved in my case

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

No branches or pull requests