DETR
读取图像时,提示:
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 |
loading annotations into memory... Done (t=0.08s) creating index... index created! loading annotations into memory... Done (t=0.06s) creating index... index created! Start training Traceback (most recent call last): File "/home/ubuntu/bigdisk/part4/DETR/main.py", line 443, in <module> main(args) File "/home/ubuntu/bigdisk/part4/DETR/main.py", line 369, in main 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__ 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) ValueError: Caught ValueError in DataLoader worker process 0. Original 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 51, in __getitem__ img, target = self.prepare(img, target) File "/home/ubuntu/bigdisk/part4/DETR/datasets/coco.py", line 84, in __call__ image_id = torch.tensor([image_id]) ValueError: too many dimensions 'str' |
这个问题的发生有个背景,从VOC转COCO的时候,出现image_id是非数字的问题,我采用脚本批量将其转为数字之后,再次读取image_id,此时会认为其类型为str。所以,只需要在读取的时候强制int即可,下面是原始代码:
1 2 3 4 5 6 7 |
def __call__(self, image, target): w, h = image.size image_id = target["image_id"] image_id = torch.tensor([image_id]) anno = target["annotations"] |
下面是修改后的:
1 2 3 4 5 6 7 |
def __call__(self, image, target): w, h = image.size image_id = target["image_id"] image_id = torch.tensor([int(image_id)]) anno = target["annotations"] |
当然,这个跟代码有关,不过原理是一样的。
本文最后更新于2022年12月3日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
很感谢博主告诉我是这么一个问题,为我查BUG剩下不少时间
@秦迪 不客气哈