最近做弱监督学习研究,进行相关分析。发现Detectron2是一个不错的框架,其中也有model zoo相当多种类的预训练模型可以拿来直接用。但是安装配置使用中碰到了许多坑。跟各位小伙伴们分享。

推荐使用Linux Ubuntu16.04以上版本安装,虚拟机不太好使

我的环境:

GPU:4 x RTX2080

Linux: Ubuntu 16.04 x64 预装doc

Nvidia驱动:440.82

CUDA:10.1

Usr: 无sudo权限

服务器安装指南:

1.强烈推荐先安装anaconda

  • 找到合适的的anaconda安装包,推荐使用国内镜像
  • Index of /anaconda/archive/ | 北京外国语大学开源软件镜像站 | BFSU Open Source Mirror
  • 推荐使用2019以上的版本,ubutun的话选择linux_x64
  • 为方便在服务器端,使用xshell操作下载,使用wget命令+复制对应的版本下载地址直接下载。
  • 小提示:安装完后需要在是否init conda时输入yes。如果没有进行这一步,参考博文安装conda时没有执行conda init_weixin_43364556的博客-CSDN博客_conda init
    /home/XXXXXX/anaconda3/bin/conda shell.bash hook >>~/.bashrc
    • 直接在终端执行,将XXXXX替换成自己的用户名
    • 之后执行source .bashrc
  • 显示(base)后完成安装

2.安装PyTorch

确保驱动和cuda已经安装好了,进入pytorch官网,选择对应版本,这里推荐使用conda安装方式,以便整个conda下的所有环境都可以使用pytorch不必重复安装

https://pytorch.org/get-started/locally/

如果cuda版本比较老,需要自己认证去寻找previous version

https://pytorch.org/get-started/previous-versions/

3.下载并配置Detectron2

Git链接:GitHub - shenyunhang/DRN-WSOD-pytorch: Enabling Deep Residual Networks for Weakly Supervised Object Detection创建合适的项目路径,通过以下执行clone

git clone https://github.com/shenyunhang/DRN-WSOD-pytorch.git

以下是官方给出的安装指导和配置要求,供参考。

Installation

Our Colab Notebook has step-by-step instructions that install detectron2. The Dockerfile also installs detectron2 with a few simple commands.

Requirements

  • Linux or macOS with Python ≥ 3.6
  • PyTorch ≥ 1.4 and torchvision that matches the PyTorch installation. You can install them together at pytorch.org to make sure of this
  • OpenCV is optional and needed by demo and visualization

Build Detectron2 from Source

gcc & g++ ≥ 5 are required. ninja is recommended for faster build. After having them, run:

python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
# (add --user if you don't have permission)# Or, to install it from a local clone:
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2# Or if you are on macOS
CC=clang CXX=clang++ python -m pip install ......

To rebuild detectron2 that's built from a local clone, use rm -rf build/ **/*.so to clean the old build first. You often need to rebuild detectron2 after reinstalling PyTorch.

Install Pre-Built Detectron2 (Linux only)

Choose from this table:

CUDA torch 1.5 torch 1.4
10.2

install

10.1

install

install

10.0

install

9.2

install

install

cpu

install

install

Note that:

  1. The pre-built package has to be used with corresponding version of CUDA and official PyTorch release. It will not work with a different version of PyTorch or a non-official build of PyTorch.
  2. Such installation is out-of-date w.r.t. master branch of detectron2. It may not be compatible with the master branch of a research project that uses detectron2 (e.g. those in projects or meshrcnn).

发现安装需要执行

python3 -m pip install -e .

其实对应的就是根目录下执行

pip install setup.py

如果在安装中有错误,请根据setup.py内要求的依赖包逐个安装

安装完后准备试一下他的功力,这里直接选用demo/中的demo.py做实验

以下是GETSTART.MD的部分内容

Getting Started with Detectron2

This document provides a brief intro of the usage of builtin command-line tools in detectron2.

For a tutorial that involves actual coding with the API, see our Colab Notebook which covers how to run inference with an existing model, and how to train a builtin model on a custom dataset.

For more advanced tutorials, refer to our documentation.

Inference Demo with Pre-trained Models

  1. Pick a model and its config file from model zoo, for example, mask_rcnn_R_50_FPN_3x.yaml.
  2. We provide demo.py that is able to run builtin standard models. Run it with:
cd demo/
python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \--input input1.jpg input2.jpg \[--other-options]--opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl

The configs are made for training, therefore we need to specify MODEL.WEIGHTS to a model from model zoo for evaluation. This command will run the inference and show visualizations in an OpenCV window.

For details of the command line arguments, see demo.py -h or look at its source code to understand its behavior. Some common arguments are:

  • To run on your webcam, replace --input files with --webcam.
  • To run on a video, replace --input files with --video-input video.mp4.
  • To run on cpu, add MODEL.DEVICE cpu after --opts.
  • To save outputs to a directory (for images) or a file (for webcam or video), use --output.

在其他博客中detectron2 + ubuntu + cpu - 走看看有对其的一点点翻译大家可以参看。

注意:这里要说的是在线下载模型文件不太好用,无论是用代理还是不用,都下载不了

所以选择model zoo中直接下载pkl与训练模型,到demo/目录https://github.com/shenyunhang/DRN-WSOD-pytorch/blob/DRN-WSOD/MODEL_ZOO.mdhttps://github.com/shenyunhang/DRN-WSOD-pytorch/blob/DRN-WSOD/MODEL_ZOO.md注意,id要对应上,然后将你要识别的图片也放在demo/下,执行命令

python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input ies.jpg --output 1.jpg --opts MODEL.WEIGHTS model_final_f10217.pkl

[12/22 01:35:08 detectron2]: Arguments: Namespace(confidence_threshold=0.5, config_file='../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml', input=['ies.jpg'], opts=['MODEL.WEIGHTS', 'model_final_f10217.pkl'], output='1.jpg', video_input=None, webcam=False)
[12/22 01:35:12 fvcore.common.checkpoint]: [Checkpointer] Loading from model_final_f10217.pkl ...
[12/22 01:35:12 fvcore.common.checkpoint]: Reading a file from 'Detectron2 Model Zoo'
  0%|                                                                                                                                    | 0/1 [00:00<?, ?it/s]/home/zhf/PJ/wsod/DRN-WSOD-pytorch/detectron2/layers/wrappers.py:226: UserWarning: This overload of nonzero is deprecated:
    nonzero()
Consider using one of the following signatures instead:
    nonzero(*, bool as_tuple) (Triggered internally at  /opt/conda/conda-bld/pytorch_1607370141920/work/torch/csrc/utils/python_arg_parser.cpp:882.)
  return x.nonzero().unbind(1)
[12/22 01:35:13 detectron2]: ies.jpg: detected 10 instances in 0.36s
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.49it/s]

完成后1.png即为输出文件,导出后查看,效果还可以,输入图片可以是任意尺寸的!

,后期会解析一下detectron2的代码结构

弱监督学习框架 Detectron2/DRN-WSOD-pytorch 在服务器/windows上配置安装及使用相关推荐

  1. 干货 | 弱监督学习框架 Snorkel 在大规模文本数据集自动标注任务中的实践

    作者简介 Jay,携程高级算法经理,关注机器学习和深度学习领域在酒店场景可落地的相关技术. 引言 近年来,得益于深度学习的巨大发展,自然语言处理(NLP)领域也爆发了多个如 BERT 等state-o ...

  2. windows上编译安装pytorch的c++扩展

    环境描述 window10 python3.6.8 [MSC v.1916 64 bit (AMD64)] pytorch 1.10.0+cu113 cuda版本 11.1 使用mingw32编译 编 ...

  3. 独家 | 2019 ICCV 收录论文:基于弱监督学习的病理影像分析框架

    论文传送门 ▼ 扫描下方二维码,或点击文末"阅读原文" 基于弱监督学习的病理影像分析框架 一.研究背景 恶性肿瘤是全球第二大死因,每年导致近千万人死亡.病理报告是肿瘤临床诊断和治疗 ...

  4. 关于弱监督学习的详细介绍——A Brief Introduction to Weakly Supervised Learning

    目录 介绍 主动学习 半监督学习 多实例学习 带噪学习 Snorkel 框架介绍 参考 介绍 在机器学习领域,学习任务可大致划分为两类,一种是监督学习,另一种是非监督学习.通常,两者都需要从包含大量训 ...

  5. Windows上python开发--2安装django框架

    Windows上python开发--2安装django框架 分类: 服务器后台开发2014-05-17 21:22 2310人阅读 评论(2) 收藏 举报 python django 上一篇文章中讲了 ...

  6. [读论文]弱监督学习的精确 3D 人脸重建:从单个图像到图像集-Accurate 3D Face Reconstruction with Weakly-Supervised Learning:From

    论文地址:Accurate 3D Face Reconstruction with Weakly-Supervised Learning:From Single Image to Image Set ...

  7. 目标检测、视觉弱监督学习、大脑多模态成像技术等CV综述来了!图像图形学发展年度报告综述专刊!...

    点击下方卡片,关注"CVer"公众号 AI/CV重磅干货,第一时间送达 点击进入-> CV 微信技术交流群 中国图象图形学学会 和中国图象图形学报联合重磅发布 2021年图像 ...

  8. ICML long talk | 达摩院开源半监督学习框架Dash

    团队模型.论文.博文.直播合集,点击此处浏览 一.论文&代码 论文链接:Dash: Semi-Supervised Learningwith DynamicThreolding 开源代码:ht ...

  9. 独家 | 日本机器学习领军人杉山将:为什么说弱监督学习是未来的热门?

    前不久结束的第三届CCAI大会,日本人工智能和机器学习领域的新一代领军人物杉山将(Masashi Sugiyama)为我们带来了一场关于弱监督机器学习的精彩演讲,这是机器学习领域少有的来自日本的声音. ...

最新文章

  1. CoRL 2020奖项公布,斯坦福获最佳论文奖,华为等摘得最佳系统论文奖
  2. 【第44题】【062题库】2019年OCP认证062考试新题
  3. Android SDCard操作(文件读写,容量计算)
  4. python画圆形螺旋线_这个Python项目,一秒生成可爱像素风图片
  5. MyEclipse 10(汉化版)安装教程
  6. ABB RAPID 程序 WorldZone 归纳
  7. 如何在OpenJDK中使用ECC
  8. Java异常持久化,Log4j进行日志的数据库持久化,说SQL语法异常。
  9. c语言数据结构插入算法说明,C语言数据结构插入算法
  10. java解析csv文件写入mysql_java读取cvs文件并导入数据库
  11. 关于博主 | 联系博主
  12. android n进入分屏代码分析_完全不用鼠标写代码!你信么?[视频]
  13. 邮件个性签名html,iphone发邮件添加个性签名方法
  14. jQuery table组织架构图表插件
  15. 专业工作站版、企业版、企业LTSC版、Servers版哪个更稳定更适合应对灾难
  16. secureCRT连接阿里云服务器
  17. CTF 每日一题 Day44 rot
  18. Endnote下载的pdf文件合并到同一个文件夹
  19. 复数和向量的函数运算
  20. 怎么查找计算机里的金蝶账套,金蝶帐套数据如何拷贝到另一台电脑上

热门文章

  1. R统计绘图-PCA详解1(princomp/principal/prcomp/rda等)
  2. Revit二次开发环境搭建(Revit 2019+Visual Studio 2017)
  3. 四、软件体系结构描述
  4. cv::imread读不出图片的解决办法
  5. android 隐私泄露 路径,一种Android应用隐私泄露漏洞检测方法与流程
  6. 小心做好个人隐私保护!别让笔记本电脑成为隐私泄露的“间谍”
  7. pfamscan 的使用_基础工具-HMMER用法
  8. PyCharm使用cxfreeze的方法
  9. 关于使用java操作doc与docx互转
  10. MySQL 官网下载地址