免费资源网 – https://freexyz.cn/
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:ProjectsER-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])© 版权声明
THE END
暂无评论内容