使用DETR
读取自己转的COCO
格式数据集的时候,出现错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
loading annotations into memory... Done (t=0.06s) creating index... index created! loading annotations into memory... Done (t=0.02s) creating index... index created! Start training Error idx: 1914 Error idx: 3631 Error idx: 6603 Error idx: 3612 Error idx: 1286 Error idx: 4989 Error idx: 6612 Error idx: 496 Error idx: 4437 Error idx: 3876 Error idx: 5219 Error idx: 1750 Error idx: 2127 Error idx: 2016 Error idx: 5546 Error idx: 3429 Error idx: 3592 Error idx: 4294 Traceback (most recent call last): File "main.py", line 443, in <module> Error idx: 3040 main(args) File "main.py", line 369, in main Error idx: 5061 train_stats = train_one_epoch( File "/home/ubuntu/bigdisk/part4/DETR/engine.py", line 42, in train_one_epoch for samples, targets in metric_logger.log_every(data_loader, print_freq, header, logger=logger): File "/home/ubuntu/bigdisk/part4/DETR/util/misc.py", line 238, in log_every for obj in iterable: File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in __next__ Error idx: 4740 data = self._next_data() File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data return self._process_data(data) File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data data.reraise() File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torch/_utils.py", line 425, in reraise raise self.exc_type(msg) KeyError: Caught KeyError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/ubuntu/bigdisk/part4/DETR/datasets/coco.py", line 44, in __getitem__ img, target = super(CocoDetection, self).__getitem__(idx) File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torchvision/datasets/coco.py", line 45, in __getitem__ image = self._load_image(id) File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torchvision/datasets/coco.py", line 37, in _load_image path = self.coco.loadImgs(id)[0]["file_name"] File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/pycocotools/coco.py", line 229, in loadImgs return [self.imgs[id] for id in ids] File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/pycocotools/coco.py", line 229, in <listcomp> return [self.imgs[id] for id in ids] KeyError: '0' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/ubuntu/bigdisk/part4/DETR/datasets/coco.py", line 48, in __getitem__ img, target = super(CocoDetection, self).__getitem__(idx) File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torchvision/datasets/coco.py", line 45, in __getitem__ image = self._load_image(id) File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/torchvision/datasets/coco.py", line 37, in _load_image path = self.coco.loadImgs(id)[0]["file_name"] File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/pycocotools/coco.py", line 229, in loadImgs return [self.imgs[id] for id in ids] File "/home/ubuntu/anaconda3/envs/DETR/lib/python3.8/site-packages/pycocotools/coco.py", line 229, in <listcomp> return [self.imgs[id] for id in ids] KeyError: '0' |
原因是image_id
包含非数字
或编号从0开始
,例如00824
这种。
所以,只需要改一下image_id
即可。
本文最后更新于2022年12月3日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!