Skip to content

Commit

Permalink
Update models (#48)
Browse files Browse the repository at this point in the history
* update models

* upload script
  • Loading branch information
ypwhs authored May 8, 2024
1 parent c3d6272 commit fa8005f
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/detection-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ hide:

# 检测模型

更新时间:2024 年 5 月

## 模型概览

### 目标检测模型
Expand Down Expand Up @@ -122,13 +124,15 @@ Attention 结构:
| YOLOv3 | 2018 | 33.7 | [![](detection-models/demo/yolov3_d53_fp16_mstrain-608_273e_coco_20210517_213542-4bc34944.jpg)](detection-models/demo/yolov3_d53_fp16_mstrain-608_273e_coco_20210517_213542-4bc34944.jpg) |
| YOLOv5s | 2022 | 37.4 | [![](detection-models/demo/yolov5s.jpg)](detection-models/demo/yolov5s.jpg) |
| YOLOv5x6 | 2022 | 55.0 | [![](detection-models/demo/yolov5x6.jpg)](detection-models/demo/yolov5x6.jpg) |
| Faster R-CNN R50 | 2015 | 40.3 | [![](detection-models/demo/faster_rcnn_r50_fpn_mstrain_3x_coco_20210524_110822-e10bd31c.jpg)](detection-models/demo/faster_rcnn_r50_fpn_mstrain_3x_coco_20210524_110822-e10bd31c.jpg) |
| Mask R-CNN R50 | 2017 | 40.9 | [![](detection-models/demo/mask_rcnn_r50_fpn_mstrain-poly_3x_coco_20210524_201154-21b550bb.jpg)](detection-models/demo/mask_rcnn_r50_fpn_mstrain-poly_3x_coco_20210524_201154-21b550bb.jpg) |
| Faster R-CNN R50 | 2015 | 38.4 | [![](detection-models/demo/faster-rcnn_r50_fpn_2x_coco_38.4.jpg)](detection-models/demo/faster-rcnn_r50_fpn_2x_coco_38.4.jpg) |
| Mask R-CNN R50 | 2017 | 39.2 | [![](detection-models/demo/mask-rcnn_r50_fpn_2x_coco_39.2.jpg)](detection-models/demo/mask-rcnn_r50_fpn_2x_coco_39.2.jpg) |
| Cascade Mask R-CNN R50 | 2019 | 44.3 | [![](detection-models/demo/cascade_mask_rcnn_r50_fpn_mstrain_3x_coco_20210628_164719-5bdc3824.jpg)](detection-models/demo/cascade_mask_rcnn_r50_fpn_mstrain_3x_coco_20210628_164719-5bdc3824.jpg) |
| DETR R50 | 2020 | 40.1 | [![](detection-models/demo/detr_r50_8x2_150e_coco_20201130_194835-2c4b8974.jpg)](detection-models/demo/detr_r50_8x2_150e_coco_20201130_194835-2c4b8974.jpg) |
| Mask2Former R50 | 2021 | 44.8 | [![](detection-models/demo/mask2former_r50_lsj_8x2_50e_coco_20220326_224516-0091ce2b.jpg)](detection-models/demo/mask2former_r50_lsj_8x2_50e_coco_20220326_224516-0091ce2b.jpg) |
| DETR R50 | 2020 | 39.9 | [![](detection-models/demo/detr_r50_8xb2-150e_coco_39.9.jpg)](detection-models/demo/detr_r50_8xb2-150e_coco_39.9.jpg) |
| Swin R50 | 2021 | 46.0 | [![](detection-models/demo/mask_rcnn_swin-t-p4-w7_fpn_ms-crop-3x_coco_20210906_131725-bacf6f7b.jpg)](detection-models/demo/mask_rcnn_swin-t-p4-w7_fpn_ms-crop-3x_coco_20210906_131725-bacf6f7b.jpg) |
| QueryInst R50 | 2021 | 47.5 | [![](detection-models/demo/queryinst_r50_fpn_300_proposals_crop_mstrain_480-800_3x_coco_20210904_101802-85cffbd8.jpg)](detection-models/demo/queryinst_r50_fpn_300_proposals_crop_mstrain_480-800_3x_coco_20210904_101802-85cffbd8.jpg) |
| DINO Swin-L | 2022 | 58.4 | [![](detection-models/demo/dino-5scale_swin-l_8xb2-36e_coco_58.4.jpg)](detection-models/demo/dino-5scale_swin-l_8xb2-36e_coco_58.4.jpg) |
| Grounding DINO Swin-L | 2023 | 59.7 | [![](detection-models/demo/grounding_dino_swin-b_finetune_16xb2_1x_coco_59.7.jpg)](detection-models/demo/grounding_dino_swin-b_finetune_16xb2_1x_coco_59.7.jpg) |

可以看到,不是 mAP 分数更高的模型就更准,目前基于 Anchor 的模型依然具备极大的优势。
本表格的数据可以使用此脚本跑出:[visualize_models_mmdet3.py](detection-models/visualize_models_mmdet3.py)

可以看到,不是 mAP 分数更高的模型就更准,目前基于 Anchor 的模型依然具备极大的优势。
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions docs/detection-models/visualize_models_mmdet3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Download mmdetection and put this script in the directory.
# git clone https://github.com/open-mmlab/mmdetection

import os.path
from glob import glob

import yaml
import mmcv
from mmdet.apis import inference_detector, init_detector
from mmdet.visualization import DetLocalVisualizer

img_path = 'demo/123.jpg'

img = mmcv.imread(img_path)

model_config_map = {}
for meta_path in glob('configs/*/metafile.yml'):
meta = yaml.safe_load(open(meta_path))
if not isinstance(meta, dict):
continue
for model in meta['Models']:
model_config_map[model['Config']] = model

config_path_list = [
'configs/grounding_dino/grounding_dino_swin-b_finetune_16xb2_1x_coco.py',
'configs/dino/dino-5scale_swin-l_8xb2-36e_coco.py',
'configs/detr/detr_r50_8xb2-150e_coco.py',
'configs/faster_rcnn/faster-rcnn_r50_fpn_2x_coco.py',
'configs/mask_rcnn/mask-rcnn_r50_fpn_2x_coco.py',
'configs/yolo/yolov3_d53_8xb8-ms-608-273e_coco.py',
]

visualizer = DetLocalVisualizer(
bbox_color=(72, 241, 72),
text_color=(200, 200, 200),
mask_color='coco',
)

for config_path in config_path_list:
model_meta = model_config_map[config_path]
print(model_meta)

checkpoint_path = model_meta['Weights']
model_filename = os.path.splitext(os.path.split(checkpoint_path)[1])[0]

score = model_meta['Results'][0]['Metrics']['box AP']
model_name = f"{model_meta['Name']}_{score}"

model = init_detector(config_path, checkpoint_path)
result = inference_detector(model, img, text_prompt='car')

visualizer.dataset_meta = model.dataset_meta
visualizer.add_datasample(
'new_result',
mmcv.bgr2rgb(img),
data_sample=result,
draw_gt=False,
out_file=f'demo/{model_name}.jpg',
pred_score_thr=0.5)

# model.show_result(
# img_path,
# result,
# score_thr=0.5,
# bbox_color=(72, 241, 72),
# mask_color='coco',
# text_color=(200, 200, 200),
# out_file=f'demo/{model_name}.jpg'
# )
69 changes: 69 additions & 0 deletions scripts/visualize_models_mmdet3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Download mmdetection and put this script in the directory.
# git clone https://github.com/open-mmlab/mmdetection

import os.path
from glob import glob

import yaml
import mmcv
from mmdet.apis import inference_detector, init_detector
from mmdet.visualization import DetLocalVisualizer

img_path = 'demo/123.jpg'

img = mmcv.imread(img_path)

model_config_map = {}
for meta_path in glob('configs/*/metafile.yml'):
meta = yaml.safe_load(open(meta_path))
if not isinstance(meta, dict):
continue
for model in meta['Models']:
model_config_map[model['Config']] = model

config_path_list = [
'configs/grounding_dino/grounding_dino_swin-b_finetune_16xb2_1x_coco.py',
'configs/dino/dino-5scale_swin-l_8xb2-36e_coco.py',
'configs/detr/detr_r50_8xb2-150e_coco.py',
'configs/faster_rcnn/faster-rcnn_r50_fpn_2x_coco.py',
'configs/mask_rcnn/mask-rcnn_r50_fpn_2x_coco.py',
'configs/yolo/yolov3_d53_8xb8-ms-608-273e_coco.py',
]

visualizer = DetLocalVisualizer(
bbox_color=(72, 241, 72),
text_color=(200, 200, 200),
mask_color='coco',
)

for config_path in config_path_list:
model_meta = model_config_map[config_path]
print(model_meta)

checkpoint_path = model_meta['Weights']
model_filename = os.path.splitext(os.path.split(checkpoint_path)[1])[0]

score = model_meta['Results'][0]['Metrics']['box AP']
model_name = f"{model_meta['Name']}_{score}"

model = init_detector(config_path, checkpoint_path)
result = inference_detector(model, img, text_prompt='car')

visualizer.dataset_meta = model.dataset_meta
visualizer.add_datasample(
'new_result',
mmcv.bgr2rgb(img),
data_sample=result,
draw_gt=False,
out_file=f'demo/{model_name}.jpg',
pred_score_thr=0.5)

# model.show_result(
# img_path,
# result,
# score_thr=0.5,
# bbox_color=(72, 241, 72),
# mask_color='coco',
# text_color=(200, 200, 200),
# out_file=f'demo/{model_name}.jpg'
# )

0 comments on commit fa8005f

Please sign in to comment.