pytorch-YOLOv4
pytorch-YOLOv4 copied to clipboard
Darknet yolov4-csp to ONNX
Hi, I try to convert yolov4-csp to ONNX by this command, but I get following result:
Then I have realized that the script does not contain any logistic function. But when I add it to here:
elif activation == 'logistic': model.add_module('logistic{0}'.format(conv_id), nn.Sigmoid())
I got results containing more wrong bboxes:
What should I change in the code to have a working yolov4-csp onnx model?
Hi Frenky & friends in Github, Thank for sharing the tool of "Darknet2ONNX". I also meet the same issue about using yolov4-csp onnx model, could u give me some suggestion?
-
yolov4-csp onnx model used:
-
yolov4 onnx model used: (seems better)
Hi Frenky & friends in Github, I use demo.py to observe the situation when just converting "yolov4-csp" into a Pytorch model, and there are many Bonding Boxs that have appeared in the results, so it should not be the isssue of converting a Pytorch into a ONNX model. ( I am not sure this is normal about the original yolov4-csp XD. But "converting a Pytorch into a ONNX model" may be OK. )
Thanks, -chayi
Hi, it should be enough to change this line according to this answer. It works for me, but I have to explore more.
Hi, I try to convert yolov4-csp to ONNX by this command, but I get following result:
Then I have realized that the script does not contain any logistic function. But when I add it to here:
elif activation == 'logistic': model.add_module('logistic{0}'.format(conv_id), nn.Sigmoid())
I got results containing more wrong bboxes:What should I change in the code to have a working yolov4-csp onnx model?
Add Sigmoid is correct, and next you need to change bxy, bwy, det_confs and cls_confs to
@jackgao0323 thanks. As far as det_confs and cls_confs, they should stay unchanged, right?
det_confs = torch.sigmoid(det_confs)
cls_confs = torch.sigmoid(cls_confs)
@jackgao0323 thanks. As far as det_confs and cls_confs, they should stay unchanged, right?
det_confs = torch.sigmoid(det_confs)
cls_confs = torch.sigmoid(cls_confs)
No, det & cls they don't need the sigmoid. Just comment the four lines on the top, and add the two lines (bxy and bwh).
@jackgao0323 @frenky-strasak Thanks so much for the discussion above, the solution worked to improve the performance of yolov4-csp. However, I realized that there is still a discrepancy between the results from running inference in darknet and onnx. Can I check if the above equations are correct?
For example, shouldnt's bwh = torch.pow(torch.sigmoid(bwh) * 2, 2) based on the equation change from yolov4 to yolov4-csp? Also shouldn't we have torch.sigmoid in the bxy equation too?
***Actually I have changed it and the results are nonsensical again. @jackgao0323 would you mind explaining how you arrived at your equation or refer me to a resource?
Also is there a way to make my results exactly the same?
@jackgao0323 @frenky-strasak Thanks so much for the discussion above, the solution worked to improve the performance of yolov4-csp. However, I realized that there is still a discrepancy between the results from running inference in darknet and onnx. Can I check if the above equations are correct?
For example, shouldnt's bwh = torch.pow(torch.sigmoid(bwh) * 2, 2) based on the equation change from yolov4 to yolov4-csp? Also shouldn't we have torch.sigmoid in the bxy equation too?
***Actually I have changed it and the results are nonsensical again. @jackgao0323 would you mind explaining how you arrived at your equation or refer me to a resource?
Also is there a way to make my results exactly the same?
I'm running into the same issue. Were you able to find a solution?