CLRNet-onnxruntime-and-tensorrt-demo
CLRNet-onnxruntime-and-tensorrt-demo copied to clipboard
Unexpected key(s) in state_dict: "heads.sample_x_indexs", "heads.prior_feat_ys", "heads.prior_ys", "heads.criterion.weight".
Hi,
I run: python torch2onnx.py <config_file> --load_from <pth_file> and get crash:-
pretrained model: https://download.pytorch.org/models/resnet101-5d3b4d8f.pth
Traceback (most recent call last):
File "torch2onnx.py", line 49, in
Any ideas? @xuanandsix Thanks!
You did not successfully replace the clr_head.py file.
cp clr_head.py in this code to CLRNet/clrnet/models/heads/ in official code.
Thanks @xuanandsix.
It seems to be the clr_head.py from this repo is being indeed loaded. I am trying to debug now - then why I still get this crash, as you say I should not. Meanwhile if you have more thoughts, let us know here.
1、By 'pip list' check if the path to the 'clrnet' package is correct.
2、Or choose to replace the clr_head.py file first before running package install (i.e. 'python setup.py build develop').
If you need training source code, it is recommended to maintain training and deployment with two environments.
A log has been upload here https://github.com/xuanandsix/CLRNet-onnxruntime-and-tensorrt-demo/blob/main/my_log/test_onnx.log My deployment process from scratch. You can view each step by search: ***@ai02
Hi @xuanandsix, I notice:
In your example "python torch2onnx.py configs/clrnet/clr_resnet18_tusimple.py --load_from tusimple_r18.pth", when I print the keys in "state_dict" from "https://github.com/xuanandsix/CLRNet-onnxruntime-and-tensorrt-demo/blob/main/torch2onnx.py#L22", I do not see these:- module.heads.sample_x_indexs module.heads.prior_feat_ys module.heads.prior_ys module.heads.criterion.weight
But I have these when I load my trained model.
So maybe this is why you are not getting my crash that I list in this issue. What do you think?
@sahamitul Have you solved this problem?
same issues,any advices?
@mengxia1994 maybe you can try other backbone. I met this problem when use resnet-18, but it worked when I use dla 34.
I found that exporting seems to work ok if I use the pretraining weights provided by https://github.com/Turoad/clrnet but if I train my own network, I get this error, with both dla34-culane and resnet18-tusimple. Not sure what's different
OK I got this working literally just by deleting the offending dict keys:
del new_state_dict["heads.sample_x_indexs"]
del new_state_dict["heads.prior_feat_ys"]
del new_state_dict["heads.prior_ys"]
del new_state_dict["heads.criterion.weight
inserted just before https://github.com/xuanandsix/CLRNet-onnxruntime-and-tensorrt-demo/blob/07a47e666d4bfca9a4c60a777c62c23828fca663/torch2onnx.py#L28
Edit. probably better to do as @AshwinAKannan suggests with strict=False
net.load_state_dict(new_state_dict, strict=False)
I passed 'strict=False'
model = load_state_dict(path, strict=False)