chongruo / detectron2-ResNeSt

A fork of Detectron2 with ResNeSt backbone
https://arxiv.org/abs/2004.08955
Apache License 2.0
385 stars 73 forks source link

RuntimeError: The size of tensor a (1741) must match the size of tensor b (4741) at non-singleton dimension 0 #18

Closed shida666 closed 4 years ago

shida666 commented 4 years ago

最近想用下ResNeSt,于是按照步骤安装了detectron2-ResNeSt,但是在运行时遇到一点问题,错误如下: Traceback (most recent call last): File "demo/demo.py", line 89, in predictions, visualized_output = demo.run_on_image(img) File "/root/detectron2-ResNeSt/demo/predictor.py", line 48, in run_on_image predictions = self.predictor(image) File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/detectron2/engine/defaults.py", line 196, in call predictions = self.model([inputs])[0] File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call result = self.forward(*input, *kwargs) File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/detectron2/modeling/meta_arch/rcnn.py", line 108, in forward return self.inference(batched_inputs) File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/detectron2/modeling/metaarch/rcnn.py", line 165, in inference proposals, = self.proposal_generator(images, features, None) File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call result = self.forward(input, **kwargs) File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/detectron2/modeling/proposal_generator/rpn.py", line 182, in forward self.training, File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/detectron2/modeling/proposal_generator/rpn_outputs.py", line 142, in find_top_rpn_proposals keep = batched_nms(boxes.tensor, scores_per_img, lvl, nms_thresh) File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/detectron2/layers/nms.py", line 17, in batched_nms return box_ops.batched_nms(boxes, scores, idxs, iou_threshold) File "/root/anaconda3/envs/pytorch1.4.0/lib/python3.6/site-packages/torchvision/ops/boxes.py", line 75, in batched_nms boxes_for_nms = boxes + offsets[:, None] RuntimeError: The size of tensor a (1741) must match the size of tensor b (4741) at non-singleton dimension 0

我的输入如果是detectron2上原有的R50-FPN,即 python demo/demo.py --config-file /root/detectron2-ResNeSt/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \

--input test_img/input/0_original.jpg test_img/input/1.jpg test_img/input/2.png test_img/input/3.png test_img/input/4.png --output test_img/output/ \ --opts MODEL.WEIGHTS /root/detectron2-ResNeSt/pretrain_model/pretrain_model/R50-FPN-1x/model_final_a54504.pkl 程序可以跑通;

但是如果输入换为ResNeSt50,即 python demo/demo.py --config-file /root/detectron2-ResNeSt/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \

--input test_img/input/0_original.jpg test_img/input/1.jpg test_img/input/2.png test_img/input/3.png test_img/input/4.png --output test_img/output/ \ --opts MODEL.WEIGHTS /root/detectron2-ResNeSt/pretrain_model/pretrain_model/ResNeSt50/mask_rcnn_ResNeSt_50_FPN_syncBN_1x-f442d863.pth 会出现以上问题。即 RuntimeError: The size of tensor a (1741) must match the size of tensor b (4741) at non-singleton dimension 0, 请问这个问题怎么解决。

shida666 commented 4 years ago

已解决,yaml文件不同于detectron2,可改为以下: python demo/demo.py --config-file /root/detectron2-ResNeSt/configs/COCO-InstanceSegmentation/mask_cascade_rcnn_R_50_FPN_syncbn_1x.yaml \ --input test_img/input/0_original.jpg test_img/input/1.jpg test_img/input/2.png test_img/input/3.png test_img/input/4.png --output test_img/output/ \ --opts MODEL.WEIGHTS /root/detectron2-ResNeSt/pretrain_model/pretrain_model/ResNeSt50/mask_rcnn_ResNeSt_50_FPN_syncBN_1x-f442d863.pth