第一次使用FasterRCNN,尝试使用开源的代码来实现object feature extraction。看了网上有很多的博文都是复现和介绍FasterRCNN,或者直接使用torchvision里面的包,这里我介绍下使用Facebook MMF实现的FasterRCNN,包括安装和使用。
第一步,建立conda环境并安装python、pytorch和torchvision,MMF要求python>=3.7,pytorch>=1.6。如果有同学不了解conda的环境构建,可以参考我的另一篇文章。此外,安装时注意各软件版本之间的匹配,否则容易出错。
第二步,执行一下命令,在conda环境下安装MMF。主要还是参考官网
git clone https://github.com/facebookresearch/mmf.git cd mmf pip install --editable .
第三步,在conda环境下安装maskrcnn,按照如下命令:
conda install ipython pip install ninja yacs cython matplotlib conda install pycocotools # 安装maskrcnn git clone https://github.com/facebookresearch/maskrcnn-benchmark.git cd maskrcnn-benchmark python setup.py build develop # 安装cv2 pip install opencv-python -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
第四步,执行特征抽取代码。详见参考
如果执行过程中,出现了如下问题,我们需要进一步解决:
①
if torch._six.PY3:AttributeError: module ‘torch._six‘ has no attribute ‘PY3‘
则,我们需要进入相应的文件,并修改内容 torch._six.PY3 为 torch._six.PY37:
vi maskrcnn-benchmark/utils/imports.py
# 修改:
if torch._six.PY3:
import importlib
import importlib.util
import sys
# 修改后:
if torch._six.PY37:
import importlib
import importlib.util
import sys
② 如果没有apex模块
ModuleNotFoundError: No module named 'apex'
则我们需要安装该模块,通过以下方式:
git clone https://github.com/NVIDIA/apex cd apex python3 setup.py install
或者下载后送入相应的文件夹进行安装。
参考文献:
https://github.com/facebookresearch/maskrcnn-benchmark/blob/main/INSTALL.md
https://gitlab.com/vedanuj/vqa-maskrcnn-benchmark/-/tree/master/
https://github.com/facebookresearch/mmf/blob/main/tools/scripts/features/extract_features_vmb.py
https://github.com/ronghanghu/vqa-maskrcnn-benchmark-m4c
https://blog.csdn.net/weixin_42782150/article/details/109820615
https://blog.csdn.net/u013679159/article/details/104288338



