FasterRCNN是业界领先的目标检测网络,它继承了FastRCNN的候选区域+目标识别架构,并在此基础上提出了候选区域网络(RPN)的概念。通过共享全图卷积特征,FasterRCNN成功实现了RPN不带来额外时间开销;而RPN的引入则将当下流行的神经网络“注意力”机制融入到了目标检测网络中。这些特性使FasterRCNN在ILSVRC以及COCO 2015等一系列竞赛中荣获第一名,同时在VGG-16等模型上具备5fps的高速率。
表 1 版本配套表
| 配套 | 版本 | 环境准备指导 |
|---|---|---|
| 机器型号 | Atlas800I A2 | - |
| AI加速芯片 | 昇腾910B4 | - |
| Python | 3.11 | - |
| mindie | 2.3.0 | - |
swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:2.3.0-800I-A2-py311-openeuler24.03-lts docker run -dit --privileged --ipc=host --name=Faster_test --shm-size=1000g \
--device=/dev/davinci_manager \
--device=/dev/devmm_svm \
--device=/dev/hisi_hdc \
-v /usr/local/sbin:/usr/local/sbin \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
-v /usr/local/Ascend/firmware:/usr/local/Ascend/firmware \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /home:/home \
-v /data:/data \
-v /tmp:/tmp \
97f9fadfa336 \
/bin/bash
docker exec -it Faster_test bash# 拉取代码仓
git clone https://gitcode.com/Ascend/ModelZoo-PyTorch.git
cd ModelZoo-PyTorch/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch
# 安装依赖
python3 -m pip install -e .
# apex安装
git clone -b master https://gitcode.com/Ascend/apex.git
cd apex/
yum install -y patch --setopt=sslverify=0
bash scripts/build.sh --python=3.11
cd apex/dist/
pip3 uninstall apex
pip3 install --upgrade apex-0.1+ascend-{version}.whl
https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-101.pkl
# 数据集
https://www.modelscope.cn/datasets/PAI/COCO2017/files
# git-lfs
https://github.com/git-lfs/git-lfs/releasesbash ./test/train_faster_rcnn_full_1p.sh --data_path=/data(绝对路径)表 2 推理性能
| 配套 | 显存+卡数 | 性能 |
|---|---|---|
| A3 | 64G*1dei | 4.47img/s |
表 2 推理性能
| 配套 | 显存+卡数 | 性能 |
|---|---|---|
| A2 | 32G*1卡 | bs=18:10.68img/s |
vim patch/npu.patch第 2649 行
package_dir = site.getusersitepackages()
else:
py_version = f'{sys.version_info.major}.{sys.version_info.minor}'
package_dir = '/usr/local/lib64/python3.11/site-packages'
return package_dirvim ModelZoo-PyTorch/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/transform.pyfrom fvcore.transforms.transform import (
CropTransform,
HFlipTransform,
NoOpTransform,
Transform,
TransformList,
)
from PIL import Image
### 增加下面一行
PIL_LINEAR = getattr(Image, "LINEAR", Image.BILINEAR)
try:
import cv2 # noqa
except ImportError:
# OpenCV is an optional dependency at the moment
pass
__all__ = [
"ExtentTransform",
"ResizeTransform",
"RotationTransform",
"ColorTransform",
"PILColorTransform",
]
class ExtentTransform(Transform):
"""
Extracts a subregion from the source image and scales it to the output size.
The fill color is used to map pixels from the source rect that fall outside
the source image.
See: https://pillow.readthedocs.io/en/latest/PIL.html#PIL.ImageTransform.ExtentTransform
"""
### 修改下面一行
def __init__(self, src_rect, output_size, interp=PIL_LINEAR, fill=0):