open-mmlab labelImg mmdetection

本文介绍了数据标注工具labelImg的安装与使用,以及mmdetection框架的配置、运行和数据集微调过程。首先通过pip或源码安装labelImg,然后使用labelme进行标注并生成COCO格式数据。接着,详细阐述了mmdetection的环境配置、预训练模型下载、数据集转换、配置文件修改、训练和测试的步骤。最后提及了mmsegmentation的相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据标柱工具介绍

labelImg

git地址: https://github.com/tzutalin/labelImg

安装(两种方法都适用于linux和mac上的conda虚拟环境下安装)

根据git上介绍,有两种安装方法:

pip包安装

pip包安装(linux上最简单的安装方法),安装命令及使用命令如下:

# 环境准备
conda create -n labelImg_1 python=3.7
conda activate labelImg_1
# linux安装
pip3 install labelImg
# linux使用vnc打开可视化界面。命令行输入如下:
labelImg
#
labelImg [IMAGE_PATH] [PRE-DEFINED CLASS FILE]

使用pip list查看安装包

pip list
Package    Version
---------- ---------
certifi    2021.10.8
labelImg   1.8.6
lxml       4.6.3
pip        21.0.1
PyQt5      5.15.5
PyQt5-Qt5  5.15.2
PyQt5-sip  12.9.0
setuptools 58.0.4
wheel      0.37.0

软件截图如下
在这里插入图片描述

从源码安装

下载源代码,准备虚拟环境

# 环境准备
conda create -n labelImg_2 python==3.7
conda activate labelImg_2
pip install PyQt5
pip install lxml
pyrcc5 -o libs/resources.py resources.qrc
# 下载
git clone https://github.com/tzutalin/labelImg
cd labelImg
# 使用
python3 labelImg.py
#
python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]

使用pip list查看安装包

pip list
Package    Version
---------- ---------
certifi    2021.10.8
lxml       4.6.3
pip        21.2.2
PyQt5      5.15.5
PyQt5-Qt5  5.15.2
PyQt5-sip  12.9.0
setuptools 58.0.4
wheel      0.37.0

软件截图如下
在这里插入图片描述

labelme

git地址: https://github.com/wkentaro/labelme

安装

安装命令如下:

conda create --name=labelme python=3.6
source activate labelme
pip install labelme

使用

直接在环境下键入

labelme

出现界面如下,此时可以打开图片路径进行标注:
在这里插入图片描述
点击Create Polygons进行标注,输入标签

在这里插入图片描述

在这里插入图片描述
点击左侧菜单栏保存,保存为json文件。

生成label数据

# 运用命令
labelme_json_to_dataset DJI_20210414132518_0423_Z.json

生成文件夹DJI_20210414132518_0423_Z_json,内容如下:
在这里插入图片描述

注:可以把多个labelme_json_to_dataset aa.json写入批处理文件中

mmdetection

git地址: https://github.com/open-mmlab/mmdetection

git clone https://github.com/open-mmlab/mmdetection

下载到服务器,更新到本地,用pycharm编辑器打开(参考https://blog.csdn.net/fighting_Kitty/article/details/121023315

配置环境

找到readme中Installation,get_started.md中详细写了环境安装,主要命令如下:

# 创建虚拟环境
conda create -n openmmlab python=3.7 -y
conda activate openmmlab
# 安装PyTorch and torchvision
#(按照自己的cuda版本(nvcc -V)
# 去pytorch官网上选https://pytorch.org/get-started/previous-versions/)
# CUDA 11.0
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
# Install MMDetection(自动或者手动,自动简单,手动适合调试研究代码)
pip install openmim
mim install mmdet

# 手动
pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 torchaudio==0.7.0  -f https://download.pytorch.org/whl/torch_stable.html
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/1.7.1+cu110/index.htm



附:cuda查看nvcc -V

nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:38_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0

运行

mkdir checkpoints
cd checkpoints
wget https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
wget https://github.com/open-mmlab/mmdetection/tree/master/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py

代码

from mmdet.apis import init_detector, inference_detector

config_file = '../configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = '../checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# init a detector
model = init_detector(config_file, checkpoint_file, device=device)
# inference the demo image
inference_detector(model, '../demo/demo.jpg')

用自己的数据集微调

下载预训练模型

mmdetection里提供了丰富的预训练权重模型,本文使用faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth,下载后放到checkpoints路径下

voc数据修改为标准的coco格式

用labelImg标注检测图片,标注数据格式为PASCAL VOC的格式,一个图片对应一个XML注文件。COCO数据格式,所有的图像数据标注信息都保存在一个JSON文件中。转换代码如下:

import json
import os, sys
import xml.etree.ElementTree as ET
import pdb;pdb.set_trace()
mode = 'test' # 这里可以改成train、val
DATA_DIR = '/home/qian/caojie/software/mmdetection/data/hotel/' + mode + '/'
ANN_DIR = DATA_DIR + 'annotations/'

# ==================== 需要修改 train or val ========================
COCO_JSON_FILE = DATA_DIR + 'hotel_' + mode + '.json'  # json save path
VOC_XMLS_DIR = DATA_DIR + 'annotations/'
# ==================================================================

if not os.path.exists(ANN_DIR):
    os.makedirs(ANN_DIR)

# coco images 的列表
images = []

# coco annotations 的列表
annotations = []

# coco categories 的列表
# If necessary, pre-define category and its id
PRE_DEFINE_CATEGORIES = {
   "background": 0, "bed": 1, "chair": 2, "curtain": 3}
categories = [
    {
   
        'id': 0,
        &#
<think>嗯,用户让我介绍如何安装MMDetection3D的v1.0.0rc6版本,使用git clone、切换分支和pip安装的命令。首先,我需要确定用户的背景。可能他们是在进行3D目标检测的研究或项目,需要用到这个框架。用户可能已经有一定的深度学习基础,但对MMDetection3D的安装流程不太熟悉。 接下来,我要检查用户的命令是否正确。他们提供的命令是克隆仓库、切换标签、然后用pip安装可编辑模式。看起来没问题,但可能需要详细解释每个步骤的作用,以及可能遇到的问题。比如,为什么要用-e选项,或者为什么需要特定版本的Python或PyTorch。 用户可能遇到的问题包括依赖项安装失败、CUDA版本不兼容,或者编译扩展时出错。需要提前考虑这些情况,并在回答中给出解决方案。例如,确保PyTorch与CUDA版本匹配,或者安装正确的mmcv-full版本。 另外,用户可能没有注意到MMDetection3D的依赖关系,比如需要先安装MMCV。这时候需要提醒他们安装mmcv-full,并且指定兼容的版本。还可能忽略安装其他依赖库,比如numpy或opencv,这些在安装时可能会报错,需要提前说明。 验证安装的部分也很重要,用户可能不知道如何确认安装是否成功,所以需要提供一个简单的测试方法,比如运行示例代码或检查版本号。同时,常见问题如编译错误、版本冲突,需要给出具体的解决步骤,例如更新setuptools或确保所有包版本一致。 还要注意用户的操作系统环境,可能是在Linux下,但如果是Windows,可能需要不同的步骤,比如安装C++构建工具。但根据原问题中的命令,用户可能使用的是Linux,所以可以主要针对Linux环境进行解答。 最后,确保回答结构清晰,分步骤说明,每个部分都有解释和注意事项,帮助用户顺利完成安装,并解决可能遇到的问题。同时,提供完整的分步操作和验证方法,让用户能够一步步跟随操作,减少出错的可能。</think>--- ### 一、命令功能概述 该操作序列用于 **安装 MMDetection3D 框架的指定版本**(v1.0.0rc6),主要包含以下步骤: 1. 克隆代码仓库 2. 切换到特定版本分支 3. 以可编辑模式安装依赖 --- ### 二、逐行命令解析 ```bash # 克隆官方仓库 git clone https://github.com/open-mmlab/mmdetection3d.git ``` - **作用**:下载 MMDetection3D 代码库到当前目录 - **注意**:需提前安装 Git(`sudo apt-get install git`) --- ```bash # 进入项目目录 cd mmdetection3d ``` - **路径要求**:默认克隆到 `mmdetection3d/` 子目录 --- ```bash # 切换至指定版本分支 git checkout v1.0.0rc6 ``` - **版本说明**:`v1.0.0rc6` 是候选发布版(Release Candidate),包含稳定功能 - **备选版本**:可通过 `git tag -l` 查看所有可用版本 --- ```bash # 以可编辑模式安装依赖 pip install -e . ``` - **`-e` 参数**:以开发模式安装,代码修改即时生效 - **依赖解析**:会自动安装 `requirements/*.txt` 中指定的依赖包 --- ### 三、系统环境要求 #### 1. 基础依赖 | 组件 | 最低要求 | 推荐版本 | |-------|-----------|------------| | Python | 3.7 | 3.8+ | | PyTorch | 1.6 | 1.9+ | | CUDA | 10.1 | 11.3+ | #### 2. 必须前置安装 ```bash # 安装 MMCV(需匹配版本) pip install mmcv-full==1.7.0 -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html ``` - **参数替换**: - `{cu_version}`:CUDA 版本(如 `cu113`) - `{torch_version}`:PyTorch 版本(如 `torch1.10`) --- ### 四、完整安装流程 ```bash # Step 1: 创建虚拟环境(推荐) conda create -n openmmlab python=3.8 conda activate openmmlab # Step 2: 安装 PyTorch conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch # Step 3: 安装 MMCV pip install mmcv-full==1.7.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html # Step 4: 克隆并安装 MMDetection3D git clone https://github.com/open-mmlab/mmdetection3d.git cd mmdetection3d git checkout v1.0.0rc6 pip install -e . ``` --- ### 五、验证安装 #### 1. 基础验证 ```bash # 检查 Python 导入是否成功 python -c "from mmdet3d import __version__; print(__version__)" ``` - **预期输出**:`1.0.0rc6` #### 2. 功能测试 ```python # 测试核心模块 import mmdet3d from mmdet3d.apis import init_model print(mmdet3d.__version__) ``` --- ### 六、常见问题解决 #### 1. **编译错误(如 nms 扩展)** - **现象**:`error: command 'gcc' failed with exit status 1` - **解决方案**: ```bash # 安装编译工具 sudo apt-get install build-essential # 更新 setuptools pip install -U setuptools ``` #### 2. **版本冲突** - **现象**:`ImportError: cannot import name 'xxx' from 'mmcv'` - **解决方法**: ```bash # 查看已安装版本 pip list | grep mmcv # 强制安装正确版本 pip install mmcv-full==1.7.0 --force-reinstall ``` #### 3. **CUDA 不兼容** - **现象**:`RuntimeError: CUDA error: no kernel image is available` - **排查步骤**: ```bash # 检查 CUDA 与 PyTorch 版本匹配性 python -c "import torch; print(torch.__version__, torch.version.cuda)" ``` --- ### 七、推荐开发配置 ```bash # 安装常用工具包 pip install ipython jupyterlab matplotlib opencv-python # 安装测试依赖 pip install pytest pytest-cov ``` --- ### 附:版本兼容性对照表 | MMDetection3D 版本 | MMCV 版本 | PyTorch 版本 | CUDA 版本 | |---------------------|------------|---------------|------------| | v1.0.0rc6 | 1.7.0 | ≥1.6, ≤1.10 | ≥10.1, ≤11.5 |
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值