浏览代码

debug post-process

yjh0410 2 年之前
父节点
当前提交
d1cae5e7c0
共有 2 个文件被更改,包括 14 次插入7 次删除
  1. 1 1
      README.md
  2. 13 6
      models/detectors/yolov7/yolov7.py

+ 1 - 1
README.md

@@ -137,7 +137,7 @@ python train.py --cuda -d coco --root path/to/COCO -v yolov1 -bs 16 --max_epoch
 
 | Model         |   Backbone         | Scale | Epoch |  FPS  | AP<sup>val<br>0.5:0.95 | AP<sup>val<br>0.5 | FLOPs<br><sup>(G) | Params<br><sup>(M) | Weight |
 |---------------|--------------------|-------|-------|-------|------------------------|-------------------|-------------------|--------------------|--------|
-| YOLOv7-T      | ELANNet-Tiny       |  640  |  300  |       |         38.0           |       56.8        |   22.6            |   7.9              | [ckpt](https://github.com/yjh0410/PyTorch_YOLO_Tutorial/releases/download/yolo_tutorial_ckpt/yolov7_t_coco.pth) |
+| YOLOv7-T      | ELANNet-Tiny       |  640  |  300  |       |         38.0           |       56.8        |   22.6            |   7.9              | [ckpt](https://github.com/yjh0410/PyTorch_YOLO_Tutorial/releases/download/yolo_tutorial_ckpt/yolov7_tiny_coco.pth) |
 | YOLOv7-L      | ELANNet-Large      |  640  |  300  |       |                        |                   |   144.6           |   44.0             |  |
 
 - *All models are trained with ImageNet pretrained weight (IP). All FLOPs are measured with a 640x640 image size on COCO val2017. The FPS is measured with batch size 1 on 3090 GPU from the model inference to the NMS operation.*

+ 13 - 6
models/detectors/yolov7/yolov7.py

@@ -93,7 +93,14 @@ class YOLOv7(nn.Module):
         all_bboxes = []
         
         for obj_pred_i, cls_pred_i, box_pred_i in zip(obj_preds, cls_preds, box_preds):
-            # (H x W x KA x C,)
+            conf_i = obj_pred_i[..., 0].sigmoid()
+            conf_keep_i = conf_i > self.conf_thresh
+
+            obj_pred_i = obj_pred_i[conf_keep_i]
+            cls_pred_i = cls_pred_i[conf_keep_i]
+            box_pred_i = box_pred_i[conf_keep_i]
+
+            # (H x W x C,)
             scores_i = (torch.sqrt(obj_pred_i.sigmoid() * cls_pred_i.sigmoid())).flatten()
 
             # Keep top k top scoring indices only.
@@ -101,13 +108,13 @@ class YOLOv7(nn.Module):
 
             # torch.sort is actually faster than .topk (at least on GPUs)
             predicted_prob, topk_idxs = scores_i.sort(descending=True)
-            topk_scores = predicted_prob[:num_topk]
+            scores = predicted_prob[:num_topk]
             topk_idxs = topk_idxs[:num_topk]
 
-            # filter out the proposals with low confidence score
-            keep_idxs = topk_scores > self.conf_thresh
-            scores = topk_scores[keep_idxs]
-            topk_idxs = topk_idxs[keep_idxs]
+            # # filter out the proposals with low confidence score
+            # keep_idxs = scores > self.conf_thresh
+            # scores = scores[keep_idxs]
+            # topk_idxs = topk_idxs[keep_idxs]
 
             anchor_idxs = torch.div(topk_idxs, self.num_classes, rounding_mode='floor')
             labels = topk_idxs % self.num_classes