Ascend-SACT/FasterRCNN
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

FasterRCNN是业界领先的目标检测网络,它继承了FastRCNN的候选区域+目标识别架构,并在此基础上提出了候选区域网络(RPN)的概念。通过共享全图卷积特征,FasterRCNN成功实现了RPN不带来额外时间开销;而RPN的引入则将当下流行的神经网络“注意力”机制融入到了目标检测网络中。这些特性使FasterRCNN在ILSVRC以及COCO 2015等一系列竞赛中荣获第一名,同时在VGG-16等模型上具备5fps的高速率。

一、准备运行环境

表 1 版本配套表

配套版本环境准备指导
机器型号Atlas800I A2-
AI加速芯片昇腾910B4-
Python3.11-
mindie2.3.0-

1.1 MindIE镜像

swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:2.3.0-800I-A2-py311-openeuler24.03-lts 

1.2 容器创建

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

1.3 安装依赖

# 拉取代码仓
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

二、下载模型权重与数据集

2.1 下载到本地

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/releases

三、模型推理使用

3.1 推理脚本

bash ./test/train_faster_rcnn_full_1p.sh --data_path=/data(绝对路径)

四、性能数据

4.1 推理性能

表 2 推理性能

配套显存+卡数性能
A364G*1dei4.47img/s

4.2 训练性能

表 2 推理性能

配套显存+卡数性能
A232G*1卡bs=18:10.68img/s

五、问题解决

5.1 Apex编译失败

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_dir

5.2 Pillow版本不匹配

vim ModelZoo-PyTorch/PyTorch/built-in/cv/detection/Faster_Mask_RCNN_for_PyTorch/detectron2/data/transforms/transform.py
from 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):