Detectron2安装教程

  • 创建虚拟环境

    conda create -n detectron2 python=3.8 -y
    
  • 激活环境

    source activate detectron2
    
  • 安装Pytorch1.9.0

    根据CUDA版本选择对应的命令安装

    # CUDA 11.1
    pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html/whl/torch_stable.html
    # CUDA 10.2
    pip install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
    # CPU only
    pip install torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
    
  • 安装Opencv

    pip install opencv-python
    
  • 安装pycocotools

    pip install pycocotools
    
  • 克隆仓库

    git clone https://github.com/facebookresearch/detectron2.git
    
  • 安装detectron2
    根据自己安装的Pytorch、CUDA版本,选择对应的 detectron2 版本安装

    # CUDA 11.1
    python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html
    
    # CUDA 10.2
    python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html
    
    # CPU
    python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.9/index.html
    

    安装完成之后,到这里环境就配置好了,下载一张图片放到 detectron2 文件夹中,用于 检验环境是否安装成功

  • 运行demo

    # 打开终端,确人是否在 detectron2 的文件夹路径下
    python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input 1.jpg --output ./result.jpg --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
    

    注意:如果使用CPU运行,在最后面加上 MODEL.DEVICE cpu 即可

    还有图片的路径,也要调整好

  • 4
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值