lyuwenyu / RT-DETR

[CVPR 2024] Official RT-DETR (RTDETR paddle pytorch), Real-Time DEtection TRansformer, DETRs Beat YOLOs on Real-time Object Detection. 🔥 🔥 🔥
Apache License 2.0
1.78k stars 186 forks source link

pytorch版本RT-DETR训练自己数据集时num_classes = 真实类别数 还是 真实类别数+1 ? #70

Open fh834625 opened 9 months ago

fh834625 commented 9 months ago

作者您好,我在使用pytorch版本rt-detr训练自己数据集时,num_classes设为 真实类别数+1 能正常训练,但设为 真实类别数 时出现以下报错,另外使用paddle版本的时候没这个问题

File "C:\pycharm project\RT-DETR-main\rtdetr_pytorch\tools..\src\zoo\rtdetr\matcher.py", line 99, in forward cost_giou = -generalized_box_iou(box_cxcywh_to_xyxy(out_bbox), box_cxcywh_to_xyxy(tgt_bbox)) File "C:\pycharm project\RT-DETR-main\rtdetr_pytorch\tools..\src\zoo\rtdetr\box_ops.py", line 52, in generalized_box_iou assert (boxes1[:, 2:] >= boxes1[:, :2]).all() RuntimeError: CUDA error: device-side assert triggered CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.

lyuwenyu commented 9 months ago

用cpu跑一下torch的代码 定位一下具体的报错位置,,

fh834625 commented 9 months ago

用cpu跑一下torch的代码 定位一下具体的报错位置,,

用cpu跑了一下,发现是匈牙利匹配出了错误,因为数据集的类别是 1到6,而预测是 0到5,index=6时报错,然后看了一下paddle版本,torch版本在读取数据的时候少了这部分 catid2clsid{1: 0, 2: 1, 3: 2, 4: 3, 5: 4, 6: 5} 导致出错

lyuwenyu commented 9 months ago

好的, torch版本自定义数据不会自动映射的 直接从json里读取id作为label

nikoaakash commented 9 months ago

got the same error. did you get the solution?

fh834625 commented 9 months ago

got the same error. did you get the solution?

write a dict label2category,and modify the coco_dataset.py in line 110: classes = [label2category[obj["category_id"]]for obj in anno] label2category = { 1: 0, 2: 1, 3: 2, 4: 3, 5: 4, 6: 5 }

nikoaakash commented 9 months ago

worked. thanks.

ghost commented 8 months ago

请问下我也遇到了这个问题,我用的visdrone数据集,里面是10类,json里的label是1~10,我按照你的解决办法,在 coco_dataset.py line 110改了这个 classes = [label2category[obj["category_id"]]for obj in anno] 在最下面改了label2category={ 1:0, 2:1, 3:2, ... 10:9 } coco_detection.yaml里num_class:10,remap_mscoco_category: false 但是还会在val的过程中出现 classes = [label2category[obj["category_id"]]for obj in anno] keyError:0 的错误

想问下有解决思路吗? 谢谢

nikoaakash commented 8 months ago

put remap_mscoco_category: True In coco_datasets.py , change dict values of name to your respective class name. if your category id begins from 0 modify label2category as above. else leave rest as it is. it should work.

fh834625 commented 8 months ago

请问下我也遇到了这个问题,我用的visdrone数据集,里面是10类,json里的label是1~10,我按照你的解决办法,在 coco_dataset.py line 110改了这个 classes = [label2category[obj["category_id"]]for obj in anno] 在最下面改了label2category={ 1:0, 2:1, 3:2, ... 10:9 } coco_detection.yaml里num_class:10,remap_mscoco_category: false 但是还会在val的过程中出现 classes = [label2category[obj["category_id"]]for obj in anno] keyError:0 的错误

想问下有解决思路吗? 谢谢

只在val出现错误的话可以检查一下验证集的标注json文件,看你的描述应该是json文件里某个category出现了0

ghost commented 8 months ago

put remap_mscoco_category: True In coco_datasets.py , change dict values of name to your respective class name. if your category id begins from 0 modify label2category as above. else leave rest as it is. it should work.

设置是这样的 label为1~10 image image image image 这样还是会报错 image 还有哪里不对吗?

ghost commented 8 months ago

请问下我也遇到了这个问题,我用的visdrone数据集,里面是10类,json里的label是1~10,我按照你的解决办法,在 coco_dataset.py line 110改了这个 classes = [label2category[obj["category_id"]]for obj in anno] 在最下面改了label2category={ 1:0, 2:1, 3:2, ... 10:9 } coco_detection.yaml里num_class:10,remap_mscoco_category: false 但是还会在val的过程中出现 classes = [label2category[obj["category_id"]]for obj in anno] keyError:0 的错误 想问下有解决思路吗? 谢谢

只在val出现错误的话可以检查一下验证集的标注json文件,看你的描述应该是json文件里某个category出现了0

val的json和train的json是一样的,看上面截图是没有0的

nikoaakash commented 8 months ago

请问下我也遇到了这个问题,我用的visdrone数据集,里面是10类,json里的label是1~10,我按照你的解决办法,在 coco_dataset.py line 110改了这个 classes = [label2category[obj["category_id"]]for obj in anno] 在最下面改了label2category={ 1:0, 2:1, 3:2, ... 10:9 } coco_detection.yaml里num_class:10,remap_mscoco_category: false 但是还会在val的过程中出现 classes = [label2category[obj["category_id"]]for obj in anno] keyError:0 的错误 想问下有解决思路吗? 谢谢

只在val出现错误的话可以检查一下验证集的标注json文件,看你的描述应该是json文件里某个category出现了0

val的json和train的json是一样的,看上面截图是没有0的

names should begin from 0. like 0 : 'pedestrian' , and so on

ghost commented 8 months ago

请问下我也遇到了这个问题,我用的visdrone数据集,里面是10类,json里的label是1~10,我按照你的解决办法,在 coco_dataset.py line 110改了这个 classes = [label2category[obj["category_id"]]for obj in anno] 在最下面改了label2category={ 1:0, 2:1, 3:2, ... 10:9 } coco_detection.yaml里num_class:10,remap_mscoco_category: false 但是还会在val的过程中出现 classes = [label2category[obj["category_id"]]for obj in anno] keyError:0 的错误 想问下有解决思路吗? 谢谢

只在val出现错误的话可以检查一下验证集的标注json文件,看你的描述应该是json文件里某个category出现了0

val的json和train的json是一样的,看上面截图是没有0的

names should begin from 0. like 0 : 'pedestrian' , and so on

image 改成这样还是有keyError:0

nikoaakash commented 8 months ago

请问下我也遇到了这个问题,我用的visdrone数据集,里面是10类,json里的label是1~10,我按照你的解决办法,在 coco_dataset.py line 110改了这个 classes = [label2category[obj["category_id"]]for obj in anno] 在最下面改了label2category={ 1:0, 2:1, 3:2, ... 10:9 } coco_detection.yaml里num_class:10,remap_mscoco_category: false 但是还会在val的过程中出现 classes = [label2category[obj["category_id"]]for obj in anno] keyError:0 的错误 想问下有解决思路吗? 谢谢

只在val出现错误的话可以检查一下验证集的标注json文件,看你的描述应该是json文件里某个category出现了0

val的json和train的json是一样的,看上面截图是没有0的

names should begin from 0. like 0 : 'pedestrian' , and so on

image 改成这样还是有keyError:0

do not change label2category. names should begin from 0 but label2category should be 1:1 , 2:2 and so on. this is because classes = [category2label[obj["category_id"]] - 1 will do the subtraction

ghost commented 8 months ago

请问下我也遇到了这个问题,我用的visdrone数据集,里面是10类,json里的label是1~10,我按照你的解决办法,在 coco_dataset.py line 110改了这个 classes = [label2category[obj["category_id"]]for obj in anno] 在最下面改了label2category={ 1:0, 2:1, 3:2, ... 10:9 } coco_detection.yaml里num_class:10,remap_mscoco_category: false 但是还会在val的过程中出现 classes = [label2category[obj["category_id"]]for obj in anno] keyError:0 的错误 想问下有解决思路吗? 谢谢

只在val出现错误的话可以检查一下验证集的标注json文件,看你的描述应该是json文件里某个category出现了0

val的json和train的json是一样的,看上面截图是没有0的

names should begin from 0. like 0 : 'pedestrian' , and so on

image 改成这样还是有keyError:0

do not change label2category. names should begin from 0 but label2category should be 1:1 , 2:2 and so on. this is because classes = [category2label[obj["category_id"]] - 1 will do the subtraction

image image I tried this but still got the error. image

nikoaakash commented 8 months ago

can you print obj['category_id'] ?

clk-ad commented 7 months ago

catid2name = { 0: 'background', 1: 'person', 2: 'bicycle', 3: 'car', 4: 'motorcycle', 5: 'airplane', 6: 'bus', 7: 'train', 8: 'truck', 9: 'boat', 10: 'traffic light', 11: 'fire hydrant', 13: 'stop sign', 14: 'parking meter', 15: 'bench', 16: 'bird', 17: 'cat', 18: 'dog', 19: 'horse', 20: 'sheep', 21: 'cow', 22: 'elephant', 23: 'bear', 24: 'zebra', 25: 'giraffe', 27: 'backpack', 28: 'umbrella', 31: 'handbag', 32: 'tie', 33: 'suitcase', 34: 'frisbee', 35: 'skis', 36: 'snowboard', 37: 'sports ball', 38: 'kite', 39: 'baseball bat', 40: 'baseball glove', 41: 'skateboard', 42: 'surfboard', 43: 'tennis racket', 44: 'bottle', 46: 'wine glass', 47: 'cup', 48: 'fork', 49: 'knife', 50: 'spoon', 51: 'bowl', 52: 'banana', 53: 'apple', 54: 'sandwich', 55: 'orange', 56: 'broccoli', 57: 'carrot', 58: 'hot dog', 59: 'pizza', 60: 'donut', 61: 'cake', 62: 'chair', 63: 'couch', 64: 'potted plant', 65: 'bed', 67: 'dining table', 70: 'toilet', 72: 'tv', 73: 'laptop', 74: 'mouse', 75: 'remote', 76: 'keyboard', 77: 'cell phone', 78: 'microwave', 79: 'oven', 80: 'toaster', 81: 'sink', 82: 'refrigerator', 84: 'book', 85: 'clock', 86: 'vase', 87: 'scissors', 88: 'teddy bear', 89: 'hair drier', 90: 'toothbrush' } 想请问一下paddle版本有 0: 'background'这个类,而pytorch版本中没有背景这个类?

AntAdventure commented 2 months ago

@ghost 你好,请问你在visdrone数据集上训练出来的指标是多少,轮次和学习率是怎样设置的