# Megengine Object Detection Models
## 介绍
本目录包含了采用MegEngine实现的如下经典网络结构,并提供了在COCO2017数据集上的完整训练和测试代码:
- [RetinaNet](https://arxiv.org/abs/1708.02002)
- [Faster R-CNN](https://arxiv.org/abs/1612.03144)
- [FreeAnchor](https://arxiv.org/abs/1909.02466)
- [FCOS](https://arxiv.org/abs/1904.01355)
- [ATSS](https://arxiv.org/abs/1912.02424)
网络在COCO2017验证集上的性能和结果如下:
| 模型 | mAP<br>@5-95 | batch<br>/gpu |
| --- | :---: | :---: |
| retinanet-res18-coco-3x-800size | 35.3 | 2 |
| retinanet-res34-coco-3x-800size | 38.4 | 2 |
| retinanet-res50-coco-3x-800size | 39.3 | 2 |
| retinanet-res101-coco-3x-800size | 41.4 | 2 |
| retinanet-resx101-coco-2x-800size | 42.3 | 2 |
| faster-rcnn-res18-coco-3x-800size | 35.7 | 2 |
| faster-rcnn-res34-coco-3x-800size | 39.6 | 2 |
| faster-rcnn-res50-coco-3x-800size | 40.1 | 2 |
| faster-rcnn-res101-coco-3x-800size | 42.6 | 2 |
| faster-rcnn-resx101-coco-2x-800size | 44.1 | 2 |
| freeanchor-res18-coco-3x-800size | 38.1 | 2 |
| freeanchor-res34-coco-3x-800size | 41.1 | 2 |
| freeanchor-res50-coco-3x-800size | 42.1 | 2 |
| freeanchor-res101-coco-3x-800size | 43.9 | 2 |
| freeanchor-resx101-coco-2x-800size | 44.9 | 2 |
| fcos-res18-coco-3x-800size | 37.6 | 2 |
| fcos-res34-coco-3x-800size | 41.0 | 2 |
| fcos-res50-coco-3x-800size | 42.2 | 2 |
| fcos-res101-coco-3x-800size | 44.3 | 2 |
| fcos-resx101-coco-2x-800size | 44.8 | 2 |
| atss-res18-coco-3x-800size | 38.3 | 2 |
| atss-res34-coco-3x-800size | 41.5 | 2 |
| atss-res50-coco-3x-800size | 42.6 | 2 |
| atss-res101-coco-3x-800size | 44.7 | 2 |
| atss-resx101-coco-2x-800size | 45.6 | 2 |
## 安装和环境配置
本目录下代码基于MegEngine v1.6,在开始运行本目录下的代码之前,请确保按照[README](../../../README.md)进行了正确的环境配置。
## 如何使用
以RetinaNet为例,模型训练好之后,可以通过如下命令测试单张图片:
```bash
python3 tools/inference.py -f configs/retinanet_res50_coco_3x_800size.py \
-w /path/to/model_weights.pkl \
-i ../../assets/cat.jpg
```
`tools/inference.py`的命令行选项如下:
- `-f`, 测试的网络结构描述文件。
- `-w`, 需要测试的模型权重。
- `-i`, 需要测试的样例图片。
使用默认图片和默认模型测试的结果见下图:
![demo image](../../assets/cat_det_out.jpg)
## 如何训练
以RetinaNet在COCO2017数据集上训练为例。
1. 在开始训练前,请确保已经下载解压好[COCO2017数据集](http://cocodataset.org/#download),
并放在合适的数据目录下,准备好的数据集的目录结构如下所示(目前默认使用COCO2017数据集):
```
/path/to/
|->coco
| |annotations
| |train2017
| |val2017
```
2. 准备预训练的`backbone`网络权重:可使用 megengine.hub 下载`megengine`官方提供的在ImageNet上训练的模型, 并存放在 `/path/to/pretrain.pkl`。
3. 开始训练:
```bash
python3 tools/train.py -f configs/retinanet_res50_coco_3x_800size.py -n 8 \
-d /path/to/COCO2017
```
`tools/train.py`的命令行选项如下:
- `-f`, 所需要训练的网络结构描述文件。
- `-n`, 用于训练的devices(gpu)数量。
- `-w`, 预训练的backbone网络权重。
- `-b`,训练时采用的`batch size`, 默认2,表示每张卡训2张图。
- `-d`, 数据集的上级目录,默认`/data/datasets`。
默认情况下模型会存在 `log-of-模型名`目录下。
## 如何测试
以RetinaNet在COCO2017数据集上测试为例。
在得到训练完保存的模型之后,可以通过tools下的test.py文件测试模型在验证集上的性能。
验证某个epoch的性能:
```bash
python3 tools/test.py -f configs/retinanet_res50_coco_3x_800size.py -n 8 \
-se 51 \
-d /path/to/COCO2017
```
验证连续若干个epoch性能:
```bash
python3 tools/test.py -f configs/retinanet_res50_coco_3x_800size.py -n 8 \
-se 51 -ee 53 \
-d /path/to/COCO2017
```
表格输出多个模型测试结果(不需要gpu,只需要提前准备模型输出的json文件):
```bash
python3 tools/test_in_table.py -f file1.py file2.py\
-j file1.json file2.json\
-d /path/to/COCO2017
```
验证某个指定weights的性能:
```bash
python3 tools/test.py -f configs/retinanet_res50_coco_3x_800size.py -n 8 \
-w /path/to/model_weights.pkl \
-d /path/to/COCO2017
```
`tools/test.py`的命令行选项如下:
- `-f`, 所需要测试的网络结构描述文件。
- `-n`, 用于测试的devices(gpu)数量。
- `-w`, 需要测试的模型权重。
- `-d`,数据集的上级目录,默认`/data/datasets`。
- `-se`,连续测试的起始epoch数,默认为最后一个epoch,该参数的值必须大于等于0且小于模型的最大epoch数。
- `-ee`,连续测试的结束epoch数,默认等于`-se`(即只测试1个epoch),该参数的值必须大于等于`-se`且小于模型的最大epoch数。
## 参考文献
- [Focal Loss for Dense Object Detection](https://arxiv.org/abs/1708.02002) Tsung-Yi Lin, Priya Goyal, Ross Girshick, Kaiming He and Piotr Dollár. IEEE International Conference on Computer Vision (ICCV), 2017.
- [Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks](https://arxiv.org/abs/1506.01497) Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Neural Information Processing Systems (NIPS), 2015.
- [Feature Pyramid Networks for Object Detection](https://arxiv.org/abs/1612.03144) Tsung-Yi Lin, Piotr Dollár, Ross Girshick, Kaiming He, Bharath Hariharan and Serge Belongie. IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017.
- [FreeAnchor: Learning to Match Anchors for Visual Object Detection](https://arxiv.org/abs/1909.02466) Xiaosong Zhang, Fang Wan, Chang Liu, Rongrong Ji and Qixiang Ye. Neural Information Processing Systems (NeurIPS), 2019.
- [FCOS: Fully Convolutional One-Stage Object Detection](https://arxiv.org/abs/1904.01355) Zhi Tian, Chunhua Shen, Hao Chen, and Tong He. IEEE International Conference on Computer Vision (ICCV), 2019.
- [Bridging the Gap Between Anchor-based and Anchor-free Detection via Adaptive Training Sample Selection](https://arxiv.org/abs/1912.02424) Shifeng Zhang, Cheng Chi, Yongqiang Yao, Zhen Lei, and Stan Z. Li. IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2020.
- [Microsoft COCO: Common Objects in Context](https://arxiv.org/abs/1405.0312) Tsung-Yi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Dollár, and C Lawrence Zitnick. European Conference on Computer Vision (ECCV), 2014.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于python采用MegEngine实现的各种主流深度学习模型代码实现 (182个子文件)
ACKNOWLEDGMENTS 13KB
setup.cfg 619B
.gitignore 321B
cat_det_out.jpg 80KB
cat.jpg 75KB
cat_seg_out.jpg 10KB
imagenet_class_info.json 35KB
LICENSE 9KB
README.md 7KB
CONTRIBUTOR_LICENSE_AGREEMENT.md 7KB
README.md 5KB
README.md 5KB
README.md 5KB
README.md 4KB
README.md 4KB
CODE_OF_CONDUCT.md 3KB
README.md 3KB
README.md 2KB
README.md 857B
Help-wanted Issue.md 697B
feature-bug-issue.md 385B
dcgan.png 161KB
model.py 30KB
utils.py 13KB
trainer.py 13KB
tokenization.py 13KB
model.py 12KB
fcos.py 12KB
atss.py 12KB
freeanchor.py 11KB
resnet.py 11KB
train.py 11KB
train.py 10KB
transforms.py 10KB
test.py 10KB
finetune.py 10KB
mrpc_dataset.py 10KB
test.py 9KB
train.py 9KB
compute_fid.py 9KB
retinanet.py 9KB
compute_kid.py 9KB
rpn.py 9KB
shufflenet.py 9KB
model.py 8KB
blocks.py 8KB
train.py 8KB
train_random.py 8KB
mobilenet_v2.py 8KB
logger.py 8KB
train.py 8KB
compute_metrics.py 7KB
fpn.py 7KB
train.py 7KB
faster_rcnn.py 7KB
calibration.py 7KB
dataset.py 7KB
inference.py 6KB
box_utils.py 6KB
gan.py 6KB
rcnn.py 6KB
anchor.py 6KB
basemodel.py 6KB
test.py 6KB
test.py 5KB
test.py 5KB
test.py 5KB
test_random.py 5KB
inception_utils.py 5KB
kid_utils.py 5KB
scheduler.py 5KB
inception_score_utils.py 4KB
deeplabv3plus.py 4KB
wgan_cifar.py 4KB
dcgan_cifar.py 4KB
simplebaseline.py 4KB
train.py 4KB
loss.py 4KB
fid_utils.py 4KB
functional.py 4KB
losses.py 4KB
inference.py 3KB
point_head.py 3KB
compute_is.py 3KB
image_loader.py 3KB
wgan_base.py 3KB
metric_log.py 3KB
utils.py 3KB
box_head.py 3KB
data_utils.py 3KB
config.py 3KB
nn.py 3KB
inference.py 2KB
inference.py 2KB
train_wgan.py 2KB
train_dcgan.py 2KB
test.py 2KB
pooler.py 2KB
hubconf.py 2KB
config_args.py 2KB
共 182 条
- 1
- 2
资源评论
- 我要当码神2022-12-11感谢大佬分享的资源给了我灵感,果断支持!感谢分享~
爱吃苹果的Jemmy
- 粉丝: 77
- 资源: 1148
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功