Grad-CAM.pytorch icon indicating copy to clipboard operation
Grad-CAM.pytorch copied to clipboard

运行RetinaNet示例 - Run the RetinaNet example

Open runnermo34 opened this issue 4 years ago • 3 comments

嗨,我尝试运行RetinaNet示例代码。 该程序开始运行,但不久后失败。 那是最后几行: Hi, I tried to run the RetinaNet sample code. The program started to run, but failed shortly after. Those are the last few lines:

feature shape:torch.Size([1, 256, 100, 100])
feature shape:torch.Size([1, 256, 50, 50])
feature shape:torch.Size([1, 256, 25, 25])
feature shape:torch.Size([1, 256, 13, 13])
feature shape:torch.Size([1, 256, 7, 7])
Traceback (most recent call last):
  File "detection/demo_retinanet.py", line 185, in <module>
    main(arguments)
  File "detection/demo_retinanet.py", line 147, in main
    mask, box, class_id = grad_cam(inputs)  # cam mask
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detection/grad_cam_retinanet.py", line 61, in __call__
    output = self.net.predict([inputs])
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detectron2/detectron2/modeling/meta_arch/retinanet.py", line 438, in predict
    results = self.inference(box_cls, box_delta, anchors, images.image_sizes)
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detectron2/detectron2/modeling/meta_arch/retinanet.py", line 335, in inference
    anchors, pred_logits_per_image, deltas_per_image, tuple(image_size)
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detectron2/detectron2/modeling/meta_arch/retinanet.py", line 367, in inference_single_image
    num_topk = min(self.topk_candidates, box_reg_i.size(0))
AttributeError: 'Boxes' object has no attribute 'size' 

有人知道,如何解决这个问题? Does anybody know, how to solve this problem?

runnermo34 avatar Jun 06 '20 10:06 runnermo34

@runnermo34 您好,麻烦发下你的pytorch 版本,detectron2版本;方便的话发下您测试的图像

yizt avatar Jun 07 '20 06:06 yizt

@runnermo34 您好,麻烦发下你的pytorch 版本,detectron2版本;方便的话发下您测试的图像

torch 1.5 detectron2 最新版

lyy-fighting avatar Jun 26 '20 15:06 lyy-fighting

嗨,我尝试运行RetinaNet示例代码。 该程序开始运行,但不久后失败。 那是最后几行: Hi, I tried to run the RetinaNet sample code. The program started to run, but failed shortly after. Those are the last few lines:

feature shape:torch.Size([1, 256, 100, 100])
feature shape:torch.Size([1, 256, 50, 50])
feature shape:torch.Size([1, 256, 25, 25])
feature shape:torch.Size([1, 256, 13, 13])
feature shape:torch.Size([1, 256, 7, 7])
Traceback (most recent call last):
  File "detection/demo_retinanet.py", line 185, in <module>
    main(arguments)
  File "detection/demo_retinanet.py", line 147, in main
    mask, box, class_id = grad_cam(inputs)  # cam mask
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detection/grad_cam_retinanet.py", line 61, in __call__
    output = self.net.predict([inputs])
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detectron2/detectron2/modeling/meta_arch/retinanet.py", line 438, in predict
    results = self.inference(box_cls, box_delta, anchors, images.image_sizes)
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detectron2/detectron2/modeling/meta_arch/retinanet.py", line 335, in inference
    anchors, pred_logits_per_image, deltas_per_image, tuple(image_size)
  File "/content/drive/My Drive/Pytorch/yizt_GradCam/detectron2/detectron2/modeling/meta_arch/retinanet.py", line 367, in inference_single_image
    num_topk = min(self.topk_candidates, box_reg_i.size(0))
AttributeError: 'Boxes' object has no attribute 'size' 

有人知道,如何解决这个问题? Does anybody know, how to solve this problem? 这个问题应该是这个代码的作者和我们使用的 Detectron2版本不同造成的,比如下面的部分: 这是在 retinanet.py中的方法:注意作者修改代码时候 参数的位置,其实是和这个不一样的,注意调换,调换过可以解决您的问题,但又会有新的问题,这个需要我们再次解决!!!回头我解决了再说吧

def inference(self, anchors, pred_logits, pred_anchor_deltas, image_sizes): """ Arguments: anchors (list[Boxes]): A list of #feature level Boxes. The Boxes contain anchors of this image on the specific feature level. pred_logits, pred_anchor_deltas: list[Tensor], one per level. Each has shape (N, Hi * Wi * Ai, K or 4) image_sizes (List[torch.Size]): the input image sizes

    Returns:
        results (List[Instances]): a list of #images elements.
    """
    results = []
    for img_idx, image_size in enumerate(image_sizes):
        pred_logits_per_image = [x[img_idx] for x in pred_logits]
        deltas_per_image = [x[img_idx] for x in pred_anchor_deltas]
        results_per_image = self.inference_single_image(
            anchors, pred_logits_per_image, deltas_per_image, tuple(image_size)
        )
        results.append(results_per_image)
    return results

lyy-fighting avatar Jun 26 '20 16:06 lyy-fighting