ubuntu20.04搭建detectron2环境

创建conda环境

conda create -n detectron2 python=3.8
conda activate detectron2

安装opencv

pip install opencv-python
pip install opencv-contrib-python

安装pytorch和cuda

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

下载并编译detectron2
注意:

  1. 如果编译成功后,重新装了pytorch,请cd到detectron2目录下执行命令rm -rf build/ **/* 删除编译的文件并重新编译
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2

运行demo
注意:请选择对应的模型和权重文件

  1. 模型在configs/COCO-InstanceSegmentation里寻找.yaml文件
  2. 权重文件在MODEL_ZOO.md里寻找
python demo/demo.py --config-file /home/wj/PythonGithub/detectron2-main/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input /home/wj/PythonGithub/detectron2-main/input/bus.jpg --opts MODEL.WEIGHTS /home/wj/PythonGithub/detectron2-main/demo/mask_rcnn_R_50_FPN_3x.pkl

注意:

  1. 在网络摄像头上运行,请把–input files 替换为–webcam
  2. 播放视频,请把–input files替换为–video-input video.mp4
  3. 要在cpu上运行,请在 -opts之后添加MODEL.DEVICE cpu-
  4. 要将输出保存到目录(用于图像)或文件(用于网络摄像头或视频),请使用–output

效果演示

图片检测
在这里插入图片描述
摄像头检测
在这里插入图片描述

相关使用教程

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值