Lite-HRNet icon indicating copy to clipboard operation
Lite-HRNet copied to clipboard

Could you provide ONNX format exporting code?

Open polor1010 opened this issue 3 years ago • 13 comments

Hi This is awesome lightweight networks!! I want to test it on other mobile device. Could you provide ONNX format exporting code? Thanks a lot!!

polor1010 avatar Apr 15 '21 06:04 polor1010

Awesome lightweight networks!! Could you provide ONNX format exporting code? Thanks~

githubBingoChen avatar Apr 15 '21 12:04 githubBingoChen

“adaptive_avg_pool2d” not support in onnx

laoxihongshi avatar Apr 19 '21 06:04 laoxihongshi

RuntimeError: Failed to export an ONNX attribute 'onnx::Gather', since it's not constant, please try to make things (e.g., kernel size) static if possible

zhepherd avatar Apr 19 '21 07:04 zhepherd

“adaptive_avg_pool2d” not support in onnx

how to convert to onnx?

zhepherd avatar Apr 19 '21 07:04 zhepherd

“adaptive_avg_pool2d” not support in onnx

how to convert to onnx?

same problem cause by pool ops, some solution:https://github.com/pytorch/pytorch/issues/34743#issuecomment-600861292 but we cant convert adaptive_avg_pool2d to avg_pool.

we can change https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L29 and https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L86 to static kernel size avg_pool,maybe need retrain this model

laoxihongshi avatar Apr 19 '21 08:04 laoxihongshi

“adaptive_avg_pool2d” not support in onnx

You can directly replace the "adaptive_avg_pool2d" with the normal average pooling with a definite pooling size. Then, it can be converted to onnx format.

yu-changqian avatar Apr 20 '21 06:04 yu-changqian

“adaptive_avg_pool2d” not support in onnx

how to convert to onnx?

same problem cause by pool ops, some solution:pytorch/pytorch#34743 (comment) but we cant convert adaptive_avg_pool2d to avg_pool.

we can change https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L29 and https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L86 to static kernel size avg_pool,maybe need retrain this model

i just have transformed onnx model, but not check,u can download from here

codylcs avatar Apr 22 '21 03:04 codylcs

“adaptive_avg_pool2d” not support in onnx

how to convert to onnx?

same problem cause by pool ops, some solution:pytorch/pytorch#34743 (comment) but we cant convert adaptive_avg_pool2d to avg_pool. we can change https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L29 and https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L86 to static kernel size avg_pool,maybe need retrain this model

i just have transformed onnx model, but not check,u can download from here

which code change have you made?

zhepherd avatar Apr 22 '21 05:04 zhepherd

“adaptive_avg_pool2d” not support in onnx

how to convert to onnx?

same problem cause by pool ops, some solution:pytorch/pytorch#34743 (comment) but we cant convert adaptive_avg_pool2d to avg_pool. we can change https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L29 and https://github.com/HRNet/Lite-HRNet/blob/hrnet/models/backbones/litehrnet.py#L86 to static kernel size avg_pool,maybe need retrain this model

i just have transformed onnx model, but not check,u can download from here

which code change have you made? the core thought is change adaptive_avg_pool2d to avg_pool,adjust inputsize and outputsize,here link may help

codylcs avatar Apr 22 '21 06:04 codylcs

i have upload lite_hrnet.py, it can get onnx model but with some warnings ,maybe not influence final result ,link

codylcs avatar Apr 27 '21 08:04 codylcs

@codylcs Thanks a lot for the scripts. So the onnx model is returning heatmaps of the shape [1, 17, 96, 72] Can you please help me getting the model predicted keypoints using the onnx model ?

Abby263 avatar Jun 23 '21 06:06 Abby263

hi,@codylcs Do we need retraining the model like litehrnet etc after changing the code as what you did? I have changed the code of litehrnet.py ,yet still the same error? what was wrong ? what should I do after change the code as you said above? It did not work at all! Maybe I should build it or any other operation to make the change effective? BR

2050airobert avatar May 30 '22 03:05 2050airobert

this is my another implementation of Lite Hrnet and I have a script to convert model to onnx. See my repo: https://github.com/viet-hoang-99/Lite_HRnet_vh

viet-hoang-99 avatar Nov 03 '22 13:11 viet-hoang-99