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

article/2025/9/24 5:45:38

最近做弱监督学习研究,进行相关分析。发现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:

CUDAtorch 1.5torch 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的代码结构


http://chatgpt.dhexx.cn/article/b0AgLJSB.shtml

相关文章

大话深度残差网络(DRN)ResNet网络原理

—— 原文发布于本人的微信公众号“大数据与人工智能Lab”&#xff08;BigdataAILab&#xff09;&#xff0c;欢迎关注。 一说起“深度学习”&#xff0c;自然就联想到它非常显著的特点“深、深、深”&#xff08;重要的事说三遍&#xff09;&#xff0c;通过很深层次的网络实现…

DRN: A Deep Reinforcement Learning Framework for News Recommendation学习

欢迎转载&#xff0c;请注明出处https://blog.csdn.net/ZJKL_Silence/article/details/85798935。 本文提出了&#xff08;基于深度Q-learning 的推荐框架&#xff09;基于强化学习的推荐系统框架来解决三个问题&#xff1a; 1&#xff09;首先&#xff0c;使用DQN网络来有效建…

【超分辨率】(DRN)Closed-loop Matters: Dual Regression Networks for Single Image Super-Resolution

论文名称&#xff1a;Closed-loop Matters: Dual Regression Networks for Single Image Super-Resolution 论文下载地址&#xff1a;https://arxiv.org/pdf/2003.07018.pdf 论文代码地址&#xff1a;https://github.com/guoyongcs/DRN 但是代码有问题 论文标题&#xff1a; 1…

CNN经典模型:深度残差网络(DRN)ResNet

一说起“深度学习”&#xff0c;自然就联想到它非常显著的特点“深、深、深”&#xff08;重要的事说三遍&#xff09;&#xff0c;通过很深层次的网络实现准确率非常高的图像识别、语音识别等能力。因此&#xff0c;我们自然很容易就想到&#xff1a;深的网络一般会比浅的网络…

2021-11-11SR-DRN

闭环问题&#xff1a;单张图像超分辨的对偶回归网络&#xff08;DRN) SR主要是要学习LR和HR之间的某种映射来重建相应的HR图像。 一、SISR存在的两个潜在的问题&#xff1a; 1.学习从LR到HR的映射是一个病态的逆问题。一张LR图像可以对应多张HR图像&#xff0c;也就是说存在…

DNN

文章目录 前向传播从感知机到神经网络DNN的基本结构DNN前向传播算法数学原理 DNN前向传播算法反向传播算法(BP)DNN反向传播算法要解决的问题 DNN反向传播算法的基本思路DNN反向传播算法过程损失函数和激活函数的选择均方差损失函数Sigmoid激活函数的问题使用交叉熵损失函数Sigm…

DRCN神经网络

1 DRCN DRCN&#xff08;Deeply-Recurisive Convolutional Network)&#xff0c;一种利用深度递归卷积网络。DRCN与之前的VDSR都是来自首尔国立大学计算机视觉实验室的工作。该网络将插值后的图像作为输入&#xff0c;并像SRCNN中一样预测目标图像。 该网络分为三个部分&…

DRM(一):什么是DRM

之前说了要一起学习一下与安全紧密相关的业务事项&#xff0c;于是这就开始了。 今天就来看看与版权保护相关的技术&#xff1a;DRM 内容基本上来自&#xff1a;【DRM架构介绍】 还是我推荐的那个号–》内核工匠&#xff0c;确实内容不错&#xff0c;学到很多。 1、DRM是什…

推荐系统强化学习DRN

文章目录 强化学习的基本概念强化学习推荐系统框架强化学习推荐模型的特点 深度强化学习推荐模型中的DQNDRN的学习过程DRN竞争梯度下降算法 强化学习的基本概念 强化学习的基本概念就是一个智能体通过与环境进行交互&#xff0c;不断学习强化自己的智力&#xff0c;来指导自己的…

DRN - 扩张残留网络(图像分类和语义分割)

DRN - 扩张残留网络&#xff08;图像分类和语义分割&#xff09; 原标题 | Review: DRN — Dilated Residual Networks (Image Classification & Semantic Segmentation) 作者 | Sik-Ho Tsang 翻译 | had_in&#xff08;电子科技大学&#xff09; 编辑 | Pita 本文回顾…

DRN——强化学习与推荐系统结合

强化学习是近年来机器学习领域非常热门的研究话题&#xff0c;它的研究起源于机器人领域&#xff0c;针对智能体在不断变化的环境 中决策和学习的过程进行建模。在智能体的学习过程中&#xff0c;会完成收集外部反馈,改变自身状态,再根据自身状态对下一步的行动进行决策&#x…

【Pytorch深度学习实战】(7)深度残差网络(DRN)

&#x1f50e;大家好&#xff0c;我是Sonhhxg_柒&#xff0c;希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流&#x1f50e; &#x1f4dd;个人主页&#xff0d;Sonhhxg_柒的博客_CSDN博客 &#x1f4c3; &#x1f381;欢迎各位→点赞…

图像超分辨率 之 DRN 论文解读与感想

图像超分辨率 之 DRN (Closed-loop Matters: Dual Regression Networks for Single Image Super-Resolution)论文解读与感想 DRN是在2020年顶会&#xff08;CVPR&#xff09;上发表的一篇想法简单&#xff0c;但是结果非常不错的文章。 先来说一下文章的切入点&#xff1a; …

关于CSRF攻击及mvc中的解决方案 [ValidateAntiForgeryToken]

一.CSRF是什么&#xff1f; CSRF&#xff08;Cross-site request forgery&#xff09;&#xff0c;中文名称&#xff1a;跨站请求伪造&#xff0c;也被称为&#xff1a;one click attack/session riding&#xff0c;缩写为&#xff1a;CSRF/XSRF。 二.CSRF可以做什么&#xff…

CSRF简介

一.CSRF是什么&#xff1f; CSRF&#xff08;Cross-site request forgery&#xff09;&#xff0c;中文名称&#xff1a;跨站请求伪造&#xff0c;也被称为&#xff1a;one click attack/session riding&#xff0c;缩写为&#xff1a;CSRF/XSRF。 二.CSRF可以做什么&#xf…

django种表单post出现CSRF verification failed( CSRF验证失败 ) 的两种解决方案

现象 表单界面如下&#xff1a; 在点击提交之后&#xff0c;出现如下错误页面&#xff1a; HTML的代码如下&#xff1a; contact_form.html <!DOCTYPE HTML PUBLIC ><html> <head><title>Contact us</title> </head><body><h1&…

Django CSRF验证失败. 请求被中断.

项目场景&#xff1a; Python版本&#xff1a;3.7 Django版本&#xff1a;3.1.7 问题描述&#xff1a; 出现了CSRF验证失败. 请求被中断. 原因分析&#xff1a; 在Django中有个设定&#xff0c;防止跨域来请求。比如有爬虫&#xff0c;爬虫不是从网站根目录开始搜寻&#x…

detail: “CSRF Failed: CSRF token missing or incorrect 问题解决方法

如果你尝试了所有方法之后还是没用&#xff0c;那定位你的Ajax方法&#xff1a; 1&#xff0c;var $crf_token $(‘[name“csrfmiddlewaretoken”]’).attr(‘value’) 2&#xff0c;headers:{“X-CSRFToken”: $crf_token} 原因分析&#xff1a; 这是由于你的django,有一个…

CSRF防御之token认证

一、CSRF是什么&#xff1f; CSRF&#xff08;Cross-site request forgery&#xff09;&#xff0c;中文名称&#xff1a;跨站请求伪造。攻击者盗用你的身份&#xff0c;以你的名义发送恶意请求。CSRF能够做的事情包括&#xff1a;以你名义发送邮件&#xff0c;发消息&#xf…

禁止访问 (403)CSRF验证失败. 请求被中断.

出现这个问题是因为django在收到表单提交过来的信息时&#xff0c;会检查提交过来的信息中是否有token,并会对token进行校验&#xff0c;如果校验通过&#xff0c;那就继续执行&#xff0c;反之就会认定这次的数据有伪造的风险。 解决方案&#xff1a; 在项目的settings.py文…