yolov9 icon indicating copy to clipboard operation
yolov9 copied to clipboard

About reparameterization.ipynb

Open wgqhandsome opened this issue 11 months ago • 11 comments

I used reparameterization.ipynb to convert the trained yolov9-c model, why does the accuracy drop significantly? Can this kind of conversion maintain the accuracy? Has anyone verified the accuracy after the conversion?

wgqhandsome avatar Mar 07 '24 14:03 wgqhandsome

You could evaluate yolov9-c.pt and yolov9-c-converted.pt, they have almost same accuracy.

WongKinYiu avatar Mar 07 '24 14:03 WongKinYiu

Do you modify nc in gelan-c.yaml and reparameterization.ipynb to match your dataset?

WongKinYiu avatar Mar 07 '24 14:03 WongKinYiu

Thank you for your response. I am honored to receive your reply, and I need to delve further into this issue. Thanks again.

wgqhandsome avatar Mar 07 '24 15:03 wgqhandsome

Do you modify nc in gelan-c.yaml and reparameterization.ipynb to match your dataset?

My task only requires identifying a single category. I trained the model corresponding to yolov9-c.yaml using the train_dual method, but did not modify the nc (number of classes) in yolov9-c.yaml. When using reparameterization.ipynb for model conversion, I set cfg='gelan-c' and initialized the Model class with ch=3 (number of channels), nc=1 (number of classes), and anchors=3 (number of anchors). Theoretically, should such settings successfully complete the model conversion?

wgqhandsome avatar Mar 11 '24 15:03 wgqhandsome

Do you modify nc in gelan-c.yaml and reparameterization.ipynb to match your dataset?

My task only requires identifying a single category. I trained the model corresponding to yolov9-c.yaml using the train_dual method, but did not modify the nc (number of classes) in yolov9-c.yaml. When using reparameterization.ipynb for model conversion, I set cfg='gelan-c' and initialized the Model class with ch=3 (number of channels), nc=1 (number of classes), and anchors=3 (number of anchors). Theoretically, should such settings successfully complete the model conversion?

Fusing layers... gelan-c summary: 387 layers, 25227859 parameters, 4035 gradients, 101.8 GFLOPs Traceback (most recent call last): File "code-object-detection/detect.py", line 232, in main(opt) File "code-object-detection/detect.py", line 227, in main run(**vars(opt)) File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "code-object-detection/detect.py", line 131, in run s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string KeyError: 4795

wgqhandsome avatar Mar 11 '24 16:03 wgqhandsome

I used reparameterization.ipynb to convert the trained yolov9-c model, why does the accuracy drop significantly? Can this kind of conversion maintain the accuracy? Has anyone verified the accuracy after the conversion?

I encountered the same problem, I converted yolov9-e.pt to yolov9-e-converted.pt, This model is trained on my own dataset, and I have modified nc. mean_p mean_r map50 map yolov9-e.pt: 0.3393 0.2703 0.3045 0.2291 yolov9-e-converted.pt: 0.3019 0.2105 0.2484 0.1838

onnx20 avatar Mar 23 '24 03:03 onnx20

I guess you do not finish the training of all epochs, and convert the temp best weights.

in this case, you have to modify

ckpt = torch.load('./yolov9-e.pt', map_location='cpu')
model.names = ckpt['model'].names
model.nc = ckpt['model'].nc

to

ckpt = torch.load('./yolov9-e.pt', map_location='cpu')
ckpt['model'] = ckpt['ema']
model.names = ckpt['model'].names
model.nc = ckpt['model'].nc

WongKinYiu avatar Mar 23 '24 05:03 WongKinYiu

I guess you do not finish the training of all epochs, and convert the temp best weights.

in this case, you have to modify

ckpt = torch.load('./yolov9-e.pt', map_location='cpu')
model.names = ckpt['model'].names
model.nc = ckpt['model'].nc

to

ckpt = torch.load('./yolov9-e.pt', map_location='cpu')
ckpt['model'] = ckpt['ema']
model.names = ckpt['model'].names
model.nc = ckpt['model'].nc

Great!your method is useful,yolov9-e.pt and yolov9-e-converted.pt have the same accuracy. But what is the reason for this situation? what is the difference between ckpt['model'] and ckpt['ema'] ? Finally, thank you very much for your work!

onnx20 avatar Mar 24 '24 09:03 onnx20

Why do errors occur when training with converted weight files?

D:\anaconda\envs\yolov9\python.exe D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py detect: weights=weights\yolov9-c-converted.pt, source=data\images, data=data\mydata_ship_coco.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1 YOLO 2024-4-9 Python-3.7.12 torch-1.13.1+cpu CPU

Fusing layers... gelan-c-class2 summary: 387 layers, 25228630 parameters, 4806 gradients Traceback (most recent call last): File "D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py", line 233, in main(opt) File "D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py", line 228, in main run(**vars(opt)) File "D:\anaconda\envs\yolov9\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py", line 130, in run s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string KeyError: 2075

mo-lx avatar Apr 09 '24 08:04 mo-lx

I guess you do not finish the training of all epochs, and convert the temp best weights.

in this case, you have to modify

ckpt = torch.load('./yolov9-e.pt', map_location='cpu')
model.names = ckpt['model'].names
model.nc = ckpt['model'].nc

to

ckpt = torch.load('./yolov9-e.pt', map_location='cpu')
ckpt['model'] = ckpt['ema']
model.names = ckpt['model'].names
model.nc = ckpt['model'].nc

I use this method,add "ckpt['model'] = ckpt['ema']",but this problem persists .what should i do

2314-long avatar Apr 17 '24 09:04 2314-long

Why do errors occur when training with converted weight files?

D:\anaconda\envs\yolov9\python.exe D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py detect: weights=weights\yolov9-c-converted.pt, source=data\images, data=data\mydata_ship_coco.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1 YOLO 2024-4-9 Python-3.7.12 torch-1.13.1+cpu CPU

Fusing layers... gelan-c-class2 summary: 387 layers, 25228630 parameters, 4806 gradients Traceback (most recent call last): File "D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py", line 233, in main(opt) File "D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py", line 228, in main run(**vars(opt)) File "D:\anaconda\envs\yolov9\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "D:/Allofdata/scientific_research/perception/Repositories/track/YOLOv9-DeepSORT-Object-Tracking-main/detect.py", line 130, in run s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string KeyError: 2075

I have met the same issue and the solution was insert 1 more line after with dt[2]:: pred = pred[0][1] if isinstance(pred[0], list) else pred[0]

tuansunday05 avatar May 13 '24 02:05 tuansunday05