stefanopini / simple-HRNet

Multi-person Human Pose Estimation with HRNet in Pytorch
GNU General Public License v3.0
579 stars 108 forks source link

How to convert to ONNX? #78

Closed Ming-FitLab closed 3 years ago

Ming-FitLab commented 3 years ago

Sorry to bother, I wanted to convert your model to ONNX version, however the onnx.export function intrigued several errors. I thought the reason might be your model was not inherited from nn.Module and the usage of numpy ndarray in your model. I tried to fix it by inheriting nn.Module and convert the ndarray to tensor where the errors were occurred. Finally I fixed all the errors but then dozens of warnings occurred. What's worse, the final .onnx file couldn't work at all. So I am wondering whether you can help me to convert the model to ONNX version.

stefanopini commented 3 years ago

Hi! My class SimpleHRNet is a (big) wrapper around the PyTorch model HRNet (my re-implemented version is in models/hrnet.py) with several handy features.

From the errors you received, I think you may have tried to convert the class SimpleHRNet instead of converting the class HRNet (which is the class that inherits from nn.Module). I think you should convert the HRNet model with the onnx exporter first, then change the model definition and loading in SimpleHRNet to load the onnx version instead of the pytorch one.

Let me know if you can complete the conversion! In that case, I'd be glad to include the onnx-based code to the repository 🙂

2050airobert commented 2 years ago

you have done the convertion?