Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export darknet weights to ONNX #7002

Open
linghu8812 opened this issue Nov 19, 2020 · 6 comments
Open

Export darknet weights to ONNX #7002

linghu8812 opened this issue Nov 19, 2020 · 6 comments

Comments

@linghu8812
Copy link

linghu8812 commented Nov 19, 2020

Hello everyone, here is a code that can convert the weights of darknet to onnx model. Now it can support the conversion of yolov4, yolov4-tiny, yolov3, yolov3-spp and yolov3-tiny darknet models. The transformed model can be transformed into tensorrt model based on onnx parser of tensorrt for inference acceleration. There are also codes for tensorrt inference in the repo.

Code file: https://github.com/linghu8812/tensorrt_inference/blob/master/project/Yolov4/export_onnx.py

After the yolo layer, transpose and concat layers are added to make the post processing of the model easier. The structure of the transpose layer is shown in the following figure:

@linghu8812 linghu8812 added the Feature-request Any feature-request label Nov 19, 2020
@AlexeyAB
Copy link
Owner

@linghu8812 Hi,
Did you try to port new model #6987 (comment)

with some changes: #6987 (comment)

@linghu8812
Copy link
Author

linghu8812 commented Nov 20, 2020

@AlexeyAB Hi,
I have tested, now the export_onnx.py can export yolov4x-mish onnx model. For the new feature new_coords, I add a sigmoid layer after the concat layer, which is also can make post processing easier. The structure of the model is shown below:

image

run this command can export the yolov4x-mish.onnx model

python3 export_onnx.py --cfg_file cfg/yolov4x-mish.cfg --weights_file yolov4x-mish.weights --output_file yolov4x-mish.onnx --sigmoid

I have tested the yolov4x-mish.onnx with my tensorrt inference code, the result is shown below, the scores of the output objects are consistent with darknet outputs:

image

@dsbyprateekg
Copy link

@linghu8812 can you please share how have you created the graphs you have mentioned above?

@linghu8812
Copy link
Author

linghu8812 commented Nov 23, 2020

@dsbyprateekg Hi, the code is here: https://github.com/linghu8812/tensorrt_inference/blob/master/project/Yolov4/export_onnx.py

@xiaochus
Copy link

@linghu8812 The generated onnx model can't used in MNN framework on mobile device, because unsupport onnx operation auto_pad='SAME_LOWER'

@linghu8812
Copy link
Author

@linghu8812 The generated onnx model can't used in MNN framework on mobile device, because unsupport onnx operation auto_pad='SAME_LOWER'

@xiaochus it may caused by make conv node, however, I am not familiar with MNN, if I know which operation MNN can supported, I can modify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants