Windows11 -MASKRCNN-部署测试

Detectron2环境配置

需要配置好相应版本的NVIDIA驱动、CUDA、Pytorch、visual studio,visual stdio2019是为了配置gcc g++的。
配置pytorch的链接.
配置CUDA的链接
在这里插入图片描述

可参考项目中的官方安装说明

搭建python 环境

conda create -n detectron2 python
conda activate detectron2

安装Cuda \CUDNN 、PyTorch、 torchvision、cudatoolkit

1、Cuda \CUDNN

可以查询自己的nvcc-v查询自己cuda版本,查看安装指南

2、 PyTorch、 torchvision、cudatoolkit

终端输入:

nvcc -V
得到输出结果,cuda版本为12.1

在这里插入图片描述

# CUDA 11.8
conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 pytorch-cuda=11.8 -c pytorch -c nvidia
# CUDA 12.1
conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 pytorch-cuda=12.1 -c pytorch -c nvidia
# CPU Only
conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 cpuonly -c pytorch
进入python测试:

import torch
import torchvision
torch.cuda.is_available()

在这里插入图片描述

错误信息

在这里插入图片描述
解决办法链接

Anaconda>DLLs,重启shell

3、detectron2环境

在此路径下,激活detectron2环境,输入:

python setup.py build develop

在这里插入图片描述
成功安装detectron2。

在安装detecteron中,遇到报错:

error: command ‘C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\nvcc.exe’ failed with exit code 1
解决办法:

找到如下文件:

detectron2\layers\csrc\nms_rotated\nms_rotated_cuda.cudetectron2\layers\csrc\nms_rotated\nms_rotated_cuda.cu

// Copyright (c) Facebook, Inc. and its affiliates.
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <c10/cuda/CUDAGuard.h>
#include <ATen/cuda/CUDAApplyUtils.cuh>
#ifdef WITH_CUDA
#include "../box_iou_rotated/box_iou_rotated_utils.h"
#endif
// TODO avoid this when pytorch supports "same directory" hipification
#ifdef WITH_HIP
#include "box_iou_rotated/box_iou_rotated_utils.h"
#endif

修改为

// Copyright (c) Facebook, Inc. and its affiliates.
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <c10/cuda/CUDAGuard.h>
#include <ATen/cuda/CUDAApplyUtils.cuh>
/*#ifdef WITH_CUDA
#include "../box_iou_rotated/box_iou_rotated_utils.h"
#endif
// TODO avoid this when pytorch supports "same directory" hipification
#ifdef WITH_HIP
#include "box_iou_rotated/box_iou_rotated_utils.h"
#endif*/
#include "box_iou_rotated/box_iou_rotated_utils.h"

修改完毕之后,再次运行 python setup.py build develop。

编译的时候failed with exit status 1错误

编译的时候,我们遇到了“command ‘…/…/bin/nvcc.exe’ failed with exit status 1”,修改策略
“…/…/detectron2/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu” 文件中#include “…” 路径错误 ,然后编译成功。

运行demo.py

python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input rgb.png --output 1.png --opts MODEL.WEIGHTS model_final_f10217.pkl
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Windows下配置 maskrcnn-benchmark 环境需要遵循以下步骤: 1. 首先,确保计算机已安装好 Python3 和 CUDA。如果没有,请先安装这些依赖项。 2. 在命令行中使用 Git 命令克隆 maskrcnn-benchmark 仓库。可以使用以下命令: ``` git clone https://github.com/facebookresearch/maskrcnn-benchmark.git ``` 3. 进入克隆的仓库目录: ``` cd maskrcnn-benchmark ``` 4. 使用以下命令创建并激活 Python 虚拟环境: ``` python -m venv .env .env\Scripts\activate ``` 5. 安装 PyTorch。可以从 PyTorch 官方网站选择适合你的 CUDA 和操作系统的版本进行安装。例如,如果你的 CUDA 版本是 10.1,可以使用以下命令安装: ``` pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -f https://download.pytorch.org/whl/cu101/torch_stable.html ``` 6. 安装依赖项。运行以下命令来安装所需的依赖项: ``` pip install -r requirements.txt ``` 7. 编译 maskrcnn_benchmark。运行以下命令完成编译: ``` python setup.py build develop ``` 8. 配置 COCO API(可选)。如果你想在 COCO 数据集上进行训练和评估,可以安装 COCO API。在命令行中运行以下命令: ``` pip install cython; pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' ``` 9. 最后,测试安装是否成功。可以运行以下命令执行一个简单的示例: ``` python demo/demo.py ``` 按照以上步骤配置 maskrcnn-benchmark 环境后,你将能够在 Windows 下使用该库进行目标检测和实例分割任务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值