未验证 提交 e31935c8 编写于 作者: X xs1997zju 提交者: GitHub

Add cam support name of PPYOLOEWithAuxHead (#7719)

* GradCAM Refinement

* ROI CAM bugfix

* Add support for blazeface, ssd, retinanet

* Change nms return_idx default value to False

* Add use_extra_data attr

* pre-commit code style

* fix yolo extra_data process

* Add cam support name of PPYOLOEWithAuxHead
上级 5731e99d
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## 1.简介 ## 1.简介
基于backbone/roi特征图计算物体预测框的cam(类激活图) 基于backbone/roi特征图计算物体预测框的cam(类激活图), 目前支持基于FasterRCNN/MaskRCNN系列, PPYOLOE系列, 以及BlazeFace, SSD, Retinanet网络。
## 2.使用方法 ## 2.使用方法
* 以PP-YOLOE为例,准备好数据之后,指定网络配置文件、模型权重地址和图片路径以及输出文件夹路径,使用脚本调用tools/cam_ppdet.py计算图片中物体预测框的grad_cam热力图。下面为运行脚本示例。 * 以PP-YOLOE为例,准备好数据之后,指定网络配置文件、模型权重地址和图片路径以及输出文件夹路径,使用脚本调用tools/cam_ppdet.py计算图片中物体预测框的grad_cam热力图。下面为运行脚本示例。
...@@ -27,7 +27,7 @@ python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer ...@@ -27,7 +27,7 @@ python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer
</center> </center>
<br><center>cam_ppyoloe/225.jpg</center></br> <br><center>cam_ppyoloe/225.jpg</center></br>
## 3. 目前支持基于FasterRCNN/MaskRCNN, PPYOLOE系列以及BlazeFace, SSD, Retinanet网络。 ## 3. 目前支持基于FasterRCNN/MaskRCNN系列, PPYOLOE系列以及BlazeFace, SSD, Retinanet网络。
* PPYOLOE网络热图可视化脚本 * PPYOLOE网络热图可视化脚本
```bash ```bash
python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer_img demo/000000014439.jpg --cam_out cam_ppyoloe --target_feature_layer_name model.backbone -o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer_img demo/000000014439.jpg --cam_out cam_ppyoloe --target_feature_layer_name model.backbone -o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams
......
# Object detection grad_cam heatmap # Object detection grad_cam heatmap
## 1.Introduction ## 1.Introduction
Calculate the cam (class activation map) of the object predict bbox based on the backbone/roi feature map Calculate the cam (class activation map) of the object predict bbox based on the backbone/roi feature map, currently supports networks based on FasterRCNN/MaskRCNN series, PPYOLOE series and BlazeFace, SSD, Retinanet.
## 2.Usage ## 2.Usage
* Taking PP-YOLOE as an example, after preparing the data, specify the network configuration file, model weight address, image path and output folder path, and then use the script to call tools/cam_ppdet.py to calculate the grad_cam heat map of the prediction box. Below is an example run script. * Taking PP-YOLOE as an example, after preparing the data, specify the network configuration file, model weight address, image path and output folder path, and then use the script to call tools/cam_ppdet.py to calculate the grad_cam heat map of the prediction box. Below is an example run script.
...@@ -27,7 +27,7 @@ python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer ...@@ -27,7 +27,7 @@ python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer
<br><center>cam_ppyoloe/225.jpg</center></br> <br><center>cam_ppyoloe/225.jpg</center></br>
## 3.Currently supports networks based on FasterRCNN/MaskRCNN, PPYOLOE series and BlazeFace, SSD, Retinanet. ## 3.Currently supports networks based on FasterRCNN/MaskRCNN series, PPYOLOE series and BlazeFace, SSD, Retinanet.
* PPYOLOE bbox heat map visualization script (with backbone featuremap) * PPYOLOE bbox heat map visualization script (with backbone featuremap)
```bash ```bash
python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer_img demo/000000014439.jpg --cam_out cam_ppyoloe -o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams python tools/cam_ppdet.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --infer_img demo/000000014439.jpg --cam_out cam_ppyoloe -o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams
......
...@@ -143,9 +143,9 @@ class BBoxCAM: ...@@ -143,9 +143,9 @@ class BBoxCAM:
# set for get extra_data before nms # set for get extra_data before nms
trainer.model.use_extra_data=True trainer.model.use_extra_data=True
# set for record the bbox index before nms # set for record the bbox index before nms
if cfg.architecture == 'FasterRCNN' or cfg.architecture == 'MaskRCNN': if cfg.architecture in ['FasterRCNN', 'MaskRCNN']:
trainer.model.bbox_post_process.nms.return_index = True trainer.model.bbox_post_process.nms.return_index = True
elif cfg.architecture == 'YOLOv3': elif cfg.architecture in ['YOLOv3', 'PPYOLOE', 'PPYOLOEWithAuxHead']:
if trainer.model.post_process is not None: if trainer.model.post_process is not None:
# anchor based YOLOs: YOLOv3,PP-YOLO # anchor based YOLOs: YOLOv3,PP-YOLO
trainer.model.post_process.nms.return_index = True trainer.model.post_process.nms.return_index = True
......
...@@ -67,7 +67,10 @@ def parse_args(): ...@@ -67,7 +67,10 @@ def parse_args():
return args return args
def run(FLAGS, cfg): def run(FLAGS, cfg):
assert cfg.architecture in ['FasterRCNN', 'MaskRCNN', 'YOLOv3', 'BlazeFace', 'SSD', 'RetinaNet'], 'Only supported cam for faster_rcnn based and yolov3 based architecture for now, the others are not supported temporarily!' assert cfg.architecture in ['FasterRCNN', 'MaskRCNN', 'YOLOv3', 'PPYOLOE',
'PPYOLOEWithAuxHead', 'BlazeFace', 'SSD', 'RetinaNet'], \
'Only supported cam for faster_rcnn based and yolov3 based architecture for now, ' \
'the others are not supported temporarily!'
bbox_cam = BBoxCAM(FLAGS, cfg) bbox_cam = BBoxCAM(FLAGS, cfg)
bbox_cam.get_bboxes_cams() bbox_cam.get_bboxes_cams()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册