HRNet / Lite-HRNet

This is an official pytorch implementation of Lite-HRNet: A Lightweight High-Resolution Network.
Apache License 2.0
833 stars 126 forks source link

Could you provide ONNX format exporting code? #3

Open polor1010 opened 3 years ago

polor1010 commented 3 years ago

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!!

githubBingoChen commented 3 years ago

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

laoxihongshi commented 3 years ago

“adaptive_avg_pool2d” not support in onnx

zhepherd commented 3 years ago

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 commented 3 years ago

“adaptive_avg_pool2d” not support in onnx

how to convert to onnx?

laoxihongshi commented 3 years ago

“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

yu-changqian commented 3 years ago

“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.

codylcs commented 3 years ago

“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

zhepherd commented 3 years ago

“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?

codylcs commented 3 years ago

“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 commented 3 years ago

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

Abby263 commented 3 years ago

@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 ?

2050airobert commented 2 years ago

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

viet-hoang-99 commented 2 years ago

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