使用Docker安装detectron2的配置方法

2024-04-16 0 1,008
目录
  • 拉取cuda116镜像
  • 创建容器
  • 安装依赖环境
  • 安装Miniconda3
  • 创建环境
  • 安装依赖库
  • 安装detectron2
  • 调用示例

Detectron2 是一个用于目标检测、分割和其他视觉识别任务的平台。

Detectron2 官网安装教程是基于 linux 安装的,在 windows 上直接安装有很多问题,下面采用 docker 方式在 windows 上安装。

拉取cuda116镜像

docker pull nvcr.io/nvidia/cuda:11.6.1-cudnn8-devel-ubuntu20.04

创建容器

docker run –gpus=all -it –name ernerf -v D:\\Projects\\ER-NeRF:/ernerf nvcr.io/nvidia/cuda:11.6.1-cudnn8-devel-ubuntu20.04

安装依赖环境

apt-get update -yq –fix-missing \\
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq –no-install-recommends \\
pkg-config \\
wget \\
cmake \\
curl \\
git \\
vim

安装Miniconda3

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh -b -u -p ~/miniconda3
~/miniconda3/bin/conda init
source ~/.bashrc

创建环境

conda create -n detectron python=3.10
conda activate detectron

安装依赖库

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 –extra-index-url https://download.pytorch.org/whl/cu113
pip install cython opencv-python opencv-python-headless

安装detectron2

git clone https://github.com/facebookresearch/detectron2.git
pip install -e detectron2

调用示例

from detectron2.config import get_cfg
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog
import cv2
# 加载配置文件
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file(\”COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml\”))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # 设置阈值
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(\”COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml\”)
# 创建预测器
predictor = DefaultPredictor(cfg)
# 加载图像
im = cv2.imread(\”./image.jpg\”)
# 进行预测
outputs = predictor(im)
# 可视化预测结果
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
v = v.draw_instance_predictions(outputs[\”instances\”].to(\”cpu\”))
cv2.imwrite(\’./output.jpg\’, v.get_image()[:, :, ::-1])

到此这篇关于使用Docker安装detectron2的文章就介绍到这了,更多相关Docker安装detectron2内容请搜索悠久资源网以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源网!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 Linux服务器 使用Docker安装detectron2的配置方法 https://www.u-9.cn/server/linux/185554.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务