trt_pose_hand icon indicating copy to clipboard operation
trt_pose_hand copied to clipboard

Convert to ONNX

Open mehdiae opened this issue 3 years ago • 2 comments

Hi,

This project is very interesting and I want to use it with DeepStream. I need to convert this model weights to ONNX file using this script in trt_pose. But it seems that the model is different and I get this error:

File "export_for_isaac.py", line 182, in <module> main(args) File "export_for_isaac.py", line 119, in main model.load_state_dict(torch.load(args.input_checkpoint)) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1223, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Sequential: Missing key(s) in state_dict: "1.cmap_conv.0.0.weight", "1.cmap_conv.0.0.bias", "1.cmap_conv.0.1.weight", "1.cmap_conv.0.1.bias", "1.cmap_conv.0.1.running_mean", "1.cmap_conv.0.1.running_var", "1.cmap_conv.0.3.weight", "1.cmap_conv.0.3.bias", "1.cmap_conv.0.4.weight", "1.cmap_conv.0.4.bias", "1.cmap_conv.0.4.running_mean", "1.cmap_conv.0.4.running_var", "1.cmap_conv.0.6.weight", "1.cmap_conv.0.6.bias", "1.cmap_conv.0.7.weight", "1.cmap_conv.0.7.bias", "1.cmap_conv.0.7.running_mean", "1.cmap_conv.0.7.running_var", "1.cmap_conv.1.weight", "1.cmap_conv.1.bias", "1.paf_conv.0.0.weight", "1.paf_conv.0.0.bias", "1.paf_conv.0.1.weight", "1.paf_conv.0.1.bias", "1.paf_conv.0.1.running_mean", "1.paf_conv.0.1.running_var", "1.paf_conv.0.3.weight", "1.paf_conv.0.3.bias", "1.paf_conv.0.4.weight", "1.paf_conv.0.4.bias", "1.paf_conv.0.4.running_mean", "1.paf_conv.0.4.running_var", "1.paf_conv.0.6.weight", "1.paf_conv.0.6.bias", "1.paf_conv.0.7.weight", "1.paf_conv.0.7.bias", "1.paf_conv.0.7.running_mean", "1.paf_conv.0.7.running_var", "1.paf_conv.1.weight", "1.paf_conv.1.bias". Unexpected key(s) in state_dict: "1.cmap_up.0.weight", "1.cmap_up.0.bias", "1.cmap_up.1.weight", "1.cmap_up.1.bias", "1.cmap_up.1.running_mean", "1.cmap_up.1.running_var", "1.cmap_up.1.num_batches_tracked", "1.cmap_up.3.weight", "1.cmap_up.3.bias", "1.cmap_up.4.weight", "1.cmap_up.4.bias", "1.cmap_up.4.running_mean", "1.cmap_up.4.running_var", "1.cmap_up.4.num_batches_tracked", "1.cmap_up.6.weight", "1.cmap_up.6.bias", "1.cmap_up.7.weight", "1.cmap_up.7.bias", "1.cmap_up.7.running_mean", "1.cmap_up.7.running_var", "1.cmap_up.7.num_batches_tracked", "1.paf_up.0.weight", "1.paf_up.0.bias", "1.paf_up.1.weight", "1.paf_up.1.bias", "1.paf_up.1.running_mean", "1.paf_up.1.running_var", "1.paf_up.1.num_batches_tracked", "1.paf_up.3.weight", "1.paf_up.3.bias", "1.paf_up.4.weight", "1.paf_up.4.bias", "1.paf_up.4.running_mean", "1.paf_up.4.running_var", "1.paf_up.4.num_batches_tracked", "1.paf_up.6.weight", "1.paf_up.6.bias", "1.paf_up.7.weight", "1.paf_up.7.bias", "1.paf_up.7.running_mean", "1.paf_up.7.running_var", "1.paf_up.7.num_batches_tracked", "1.cmap_att.weight", "1.cmap_att.bias", "1.paf_att.weight", "1.paf_att.bias", "1.cmap_conv.weight", "1.cmap_conv.bias", "1.paf_conv.weight", "1.paf_conv.bias".

Have you changed resnet18_baseline architecture?

mehdiae avatar Mar 31 '21 17:03 mehdiae

Hi @mehdiae, have you found a solution for it?

soerenbrockmann avatar Jul 26 '21 16:07 soerenbrockmann

I found a solution. The model name has to be in a specific format I guess. So I just renamed the hand pose model equal to the human pose model and converted the model with this command:

hand_pose_resnet18_att_244_244.pth >>>> resnet18_baseline_att_244x244_A_epoch_249.pth

python3 export_for_isaac.py --input_checkpoint resnet18_baseline_att_244x244_A_epoch_249.pth --input_topology hand_pose.json

Input model is not specified, using resnet18_baseline_att as a default. Input width/height are not specified, using 244x244 as a default. Output path is not specified, using resnet18_baseline_att_244x244_A_epoch_249.onnx as a default. Successfully completed convertion of resnet18_baseline_att_244x244_A_epoch_249.pth to resnet18_baseline_att_244x244_A_epoch_249.onnx.

soerenbrockmann avatar Jul 26 '21 17:07 soerenbrockmann