栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Detectron2安装与测试

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/990918.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号