roytseng-tw / Detectron.pytorch

A pytorch implementation of Detectron. Both training from scratch and inferring directly from pretrained Detectron weights are available.
MIT License
2.82k stars 544 forks source link

'Detectron.pytorch/lib/utils/detectron_weight_helper.py' can be used to inference masks,but can't inference keypoints. #21

Closed tagelian closed 6 years ago

tagelian commented 6 years ago

Correctly inference masks: (cuipt) cui@DemonHunters:~/mask-rcnn.pytorch$ python tools/infer_simple.py --dataset coco --cfg configs/e2e_mask_rcnn_R-101-FPN_2x.yaml --load_detectron data/model_final.pkl --image_dir demo/sample_images Called with args: Namespace(cfg_file='configs/e2e_mask_rcnn_R-101-FPN_2x.yaml', cuda=True, dataset='coco', image_dir='demo/sample_images', images=None, load_ckpt=None, load_detectron='data/model_final.pkl', merge_pdfs=True, output_dir='infer_outputs', set_cfgs=[]) load cfg from file: configs/e2e_mask_rcnn_R-101-FPN_2x.yaml loading detectron weights data/model_final.pkl img 0 person 0.999168 img 1 suitcase 0.741572 chair 0.996991 chair 0.995423 chair 0.974603 chair 0.902452 chair 0.748457 book 0.762648 chair 0.9888 clock 0.992333 img 2 train 0.99889 person 0.826093 img 3 car 0.994156 car 0.999019 truck 0.839317 car 0.995135 car 0.9096 traffic light 0.984154 car 0.99167 car 0.995001 car 0.981888 however, can't inference keyoints, so how to modify 'detectron_weight_helper.py' to inference keypoints? `(cuipt) cui@DemonHunters:~/mask-rcnn.pytorch$ python tools/infer_simple.py --dataset keypoints_coco \

--cfg configs/e2e_mask_rcnn_R-101-FPN_2x.yaml \ --load_detectron data/model_final.pkl \ --image_dir demo/sample_images_keypoints Called with args: Namespace(cfg_file='configs/e2e_mask_rcnn_R-101-FPN_2x.yaml', cuda=True, dataset='keypoints_coco', image_dir='demo/sample_images_keypoints', images=None, load_ckpt=None, load_detectron='data/model_final.pkl', merge_pdfs=True, output_dir='infer_outputs', set_cfgs=[]) load cfg from file: configs/e2e_mask_rcnn_R-101-FPN_2x.yaml loading detectron weights data/model_final.pkl Traceback (most recent call last): File "tools/infer_simple.py", line 176, in main() File "tools/infer_simple.py", line 128, in main load_detectron_weight(maskRCNN, args.load_detectron) File "/home/cui/mask-rcnn.pytorch/lib/utils/detectron_weight_helper.py", line 21, in load_detectron_weight ptensor.copy(torch.Tensor(src_blobs[d_name])) RuntimeError: invalid argument 2: sizes do not match at /pytorch/torch/lib/THC/generic/THCTensorCopy.c:51 `

roytseng-tw commented 6 years ago

You used the wrong config file. You should use the corresponding keypoint rcnn config file to the detectron pretrained weights.

tagelian commented 6 years ago

sorry, i was too careless. Anyway, thank you.

QUJIJI commented 4 years ago

@roytseng-tw @tasselcui

1. Sorry, I am facing the same problem. I think I used the correct config file. Could you tell me how can I do to solve it.

python tools/infer_simple.py --dataset coco --cfg configs/baselines/e2e_keypoint_rcnn_R-50-FPN_s1x.yaml --load_detectron data/pretrained_model/model_e2e_s1x.pkl --image_dir ./demo/sample_images_keypoints --output_dir ./visualization

2.torch==0.3.1 torchvision==0.2.1 cuda9.0 python3.5.1+

Pretrained Model: resnet50_caffe.pth

model from : End-to-End Keypoint-Only Mask R-CNN Baselines--|R-50-FPN | Kps | s1x | 2 | 9.0 | 0.828 | 29.9 | 0.096 + 0.089 | 54.3 | - | 65.4 | - | 37697714 | model | boxes | kps|

https://dl.fbaipublicfiles.com/detectron/37697714/12_2017_baselines/e2e_keypoint_rcnn_R-50-FPN_s1x.yaml.08_44_03.qrQ0ph6M/output/train/keypoints_coco_2014_train%3Akeypoints_coco_2014_valminusminival/generalized_rcnn/model_final.pkl

3.wrong code

(detectron) (base) lh@lh:~/Detectron.pytorch$ python tools/infer_simple.py --dataset coco --cfg configs/baselines/e2e_keypoint_rcnn_R-50-FPN_s1x.yaml --load_detectron data/pretrained_model/model_e2e_s1x.pkl --image_dir ./demo/sample_images_keypoints --output_dir ./visualization Called with args: Namespace(cfg_file='configs/baselines/e2e_keypoint_rcnn_R-50-FPN_s1x.yaml', cuda=True, dataset='coco', image_dir='./demo/sample_images_keypoints', images=None, load_ckpt=None, load_detectron='data/pretrained_model/model_e2e_s1x.pkl', merge_pdfs=True, output_dir='./visualization', set_cfgs=[]) load cfg from file: configs/baselines/e2e_keypoint_rcnn_R-50-FPN_s1x.yaml /home/lh/Detectron.pytorch/lib/core/config.py:1037: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. yaml_cfg = AttrDict(yaml.load(f)) loading detectron weights data/pretrained_model/model_e2e_s1x.pkl Traceback (most recent call last): File "tools/infer_simple.py", line 176, in main() File "tools/infer_simple.py", line 128, in main load_detectron_weight(maskRCNN, args.load_detectron) File "/home/lh/Detectron.pytorch/lib/utils/detectron_weight_helper.py", line 21, in load_detectron_weight ptensor.copy(torch.Tensor(src_blobs[d_name])) RuntimeError: invalid argument 2: sizes do not match at /pytorch/torch/lib/THC/generic/THCTensorCopy.c:51