使用mmdet
的时候遇到问题:RuntimeError: Expected object of scalar type Byte but got scalar type Bool for argument #2 'other' in call to _th_and
2021-05-20 23:14:34,287 - INFO - Distributed training: False loading annotations into memory... Done (t=1.78s) creating index... index created! 2021-05-20 23:15:02,674 - INFO - Start running, host: sipl@sipl-Z590-UD, work_dir: /home/sipl/4T/ReDet-master/tools/work_dirs/ReDet_re50_refpn_1x_dota1_ms 2021-05-20 23:15:02,674 - INFO - workflow: [('train', 1)], max: 12 epochs Traceback (most recent call last): File "/home/sipl/4T/ReDet-master/tools/train.py", line 97, in <module> main() File "/home/sipl/4T/ReDet-master/tools/train.py", line 93, in main logger=logger) File "/home/sipl/4T/ReDet-master/mmdet/apis/train.py", line 61, in train_detector _non_dist_train(model, dataset, cfg, validate=validate) File "/home/sipl/4T/ReDet-master/mmdet/apis/train.py", line 197, in _non_dist_train runner.run(data_loaders, cfg.workflow, cfg.total_epochs) File "/home/sipl/anaconda3/envs/redet/lib/python3.7/site-packages/mmcv/runner/runner.py", line 358, in run epoch_runner(data_loaders[i], **kwargs) File "/home/sipl/anaconda3/envs/redet/lib/python3.7/site-packages/mmcv/runner/runner.py", line 264, in train self.model, data_batch, train_mode=True, **kwargs) File "/home/sipl/4T/ReDet-master/mmdet/apis/train.py", line 39, in batch_processor losses = model(**data) File "/home/sipl/anaconda3/envs/redet/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/home/sipl/anaconda3/envs/redet/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 150, in forward return self.module(*inputs[0], **kwargs[0]) File "/home/sipl/anaconda3/envs/redet/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/home/sipl/4T/ReDet-master/mmdet/models/detectors/base_new.py", line 95, in forward return self.forward_train(img, img_meta, **kwargs) File "/home/sipl/4T/ReDet-master/mmdet/models/detectors/ReDet.py", line 143, in forward_train *rpn_loss_inputs, gt_bboxes_ignore=gt_bboxes_ignore) File "/home/sipl/4T/ReDet-master/mmdet/models/anchor_heads/rpn_head.py", line 51, in loss gt_bboxes_ignore=gt_bboxes_ignore) File "/home/sipl/4T/ReDet-master/mmdet/models/anchor_heads/anchor_head.py", line 177, in loss sampling=self.sampling) File "/home/sipl/4T/ReDet-master/mmdet/core/anchor/anchor_target.py", line 63, in anchor_target unmap_outputs=unmap_outputs) File "/home/sipl/4T/ReDet-master/mmdet/core/utils/misc.py", line 24, in multi_apply return tuple(map(list, zip(*map_results))) File "/home/sipl/4T/ReDet-master/mmdet/core/anchor/anchor_target.py", line 108, in anchor_target_single cfg.allowed_border) File "/home/sipl/4T/ReDet-master/mmdet/core/anchor/anchor_target.py", line 173, in anchor_inside_flags (flat_anchors[:, 2] < img_w + allowed_border) & \ RuntimeError: Expected object of scalar type Byte but got scalar type Bool for argument #2 'other' in call to _th_and
解决方法:
打开上述anchor_target.py
文件,然后修改下面几行为:
def anchor_inside_flags(flat_anchors, valid_flags, img_shape, allowed_border=0): img_h, img_w = img_shape[:2] if allowed_border >= 0: inside_flags = valid_flags & \ (flat_anchors[:, 0] >= -allowed_border).type(torch.uint8) & \ (flat_anchors[:, 1] >= -allowed_border).type(torch.uint8) & \ (flat_anchors[:, 2] < img_w + allowed_border).type(torch.uint8) & \ (flat_anchors[:, 3] < img_h + allowed_border).type(torch.uint8) else: inside_flags = valid_flags return inside_flags
本文最后更新于2021年5月20日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!