Detectron2安装与测试

刚刚接触detectron2框架,总的来讲该框架由Facebook开源,质量还是非常不错的,值得学习。今天就对安装和测试遇到的一些问题进行整理和总结。后期会持续更新。

Detectron2安装

Detectron2项目链接:https://github.com/facebookresearch/detectron2
官方安装教程:https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md

Requirements

Python ≥ 3.6 (本实验在Ubuntu16.04下进行,使用Python3.7)
Pytorch ≥ 1.5 对应版本的 torchvision(本实验安装Pytorch 1.6,torchvision 0.7)
CUDA 10.1 (请选择与Pytorch匹配的cudatoolkit版本,以便成功安装框架)
GCC >= 4.9(这个是C/C++编译环境的要求,如果不对,在编译过程基本就会失败)

环境安装

anaconda创建环境

conda create -n detectron2 python=3.7
conda activate detectron2

安装pytorch 1.6 cuda10.1

conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch

#测试一下
import torch, torchvision
print(torch.__version__, torch.cuda.is_available()) 

安装其他依赖项

pip install cython pyyaml==5.1
pip install opencv-python==3.4.2
pip install cython
# fvcore 本实验安装的是下面版本,也可以参考官方安装教程安装其他版本:https://github.com/facebookresearch/fvcore/
pip install fvcore==0.1.1.post20200716
# 安装pycocotools,如果下面代码运行报错,可以参考链接进行安装:https://blog.csdn.net/xiongzai2016/article/details/106855544
pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'

安装detectron2

# 从本地克隆安装
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2

这样下载的detectron2是最新版本,由于官方安装文档中要求PyTorch ≥ 1.8 ,所以安装的时候会报错。可以访问detectron2的历史版本链接:https://github.com/facebookresearch/detectron2/releases
根据安装的PyTorch和cuda版本来安装对应版本的detectron2,下面是PyTorch1.6对应的安装命令行:

python -m pip install detectron2==0.4 -f \
  https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.6/index.html

测试-实例分割

在detectron2文件夹中新建一个testimage文件夹,存入几张测试图片。
在这里插入图片描述

运行demo.py

python demo/demo.py \
--config-file ./configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
--input ./testimage/2007_003020.jpg --output ./output/ \
--opts MODEL.WEIGHTS ./model/model_final_f10217.pkl

config-file :configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml 这个是配置信息,detectron2那个文件夹里面已经有了。
input: ./testimage/2007_003020.jpg 测试图像的路径。
output: 自己定义一个输出路径。
opts :MODEL.WEIGHTS models/model_final_f10217.pkl 这是训练好的模型,根据自己的要求去model zoom 下载就可以了。也可以直接设置成MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl 有时间下载速度有时会很慢,影响测试速度,所以还是提前下载好。

看看测试结果:

在这里插入图片描述

训练测试

使用自带的小版本数据集,运行./datasets/prepare_for_tests.sh,然后执行./dev/run_instant_tests.sh,如果出现下面的结果,恭喜都安装成功了。以下是其他博主的运行结果截图:
在这里插入图片描述

参考文章:
原文链接:https://blog.csdn.net/weixin_41298484/article/details/119914362
原文链接:https://blog.csdn.net/XX_123_1_RJ/article/details/103779787
原文链接:https://blog.csdn.net/qq_33047753/article/details/107022768

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值