使用Docker安裝detectron2的配置方法
Detectron2 是一個用于目標檢測、分割和其他視覺識別任務的平臺。
Detectron2 官網(wǎng)安裝教程是基于 linux 安裝的,在 windows 上直接安裝有很多問題,下面采用 docker 方式在 windows 上安裝。
拉取cuda116鏡像
docker pull nvcr.io/nvidia/cuda:11.6.1-cudnn8-devel-ubuntu20.04
創(chuàng)建容器
docker run --gpus=all -it --name ernerf -v D:\Projects\ER-NeRF:/ernerf nvcr.io/nvidia/cuda:11.6.1-cudnn8-devel-ubuntu20.04
安裝依賴環(huán)境
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
創(chuàng)建環(huán)境
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")
# 創(chuàng)建預測器
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內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Rocky Linux 9.2下使用dnf安裝Docker全流程指南
Docker 是當前最流行的容器化平臺,本文以 Rocky Linux 9.2 為例,詳細介紹如何使用 dnf 命令安裝 Docker,完成配置并進行基礎使用,希望對大家有所幫助2025-08-08
docker 安裝 rocketmq + dashboard的實現(xiàn)
本文主要介紹了docker 安裝 rocketmq + dashboard的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2026-05-05
在wsl-ubuntu中如何通過 docker 啟動 gpu-jupyter
這篇文章主要介紹了在wsl-ubuntu中如何通過 docker 啟動 gpu-jupyter,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01
解決運行Docker鏡像報錯:version `GLIBC_2.32‘ not found
文章介紹了解決Docker鏡像運行時因GLIBC版本不匹配導致的錯誤,建議使用AlpineLinux作為基礎鏡像,并在其中安裝所需的運行時庫,作者還分享了個人經(jīng)驗,提醒讀者嘗試其他方法無效后可以尋求幫助2024-12-12

