• Stars
    star
    266
  • Rank 153,269 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔄 A tool for object detection and image segmentation dataset format conversion.

YOLO2COCO

简体中文 | English

🎉 推出知识星球RapidAI私享群,这里的提问会优先得到回答和支持,也会享受到RapidAI组织后续持续优质的服务。欢迎大家的加入。

labelImg标注yolo格式数据 → YOLOV5格式

  • labelImg库标注的yolo数据格式一键转换为YOLOV5格式数据

  • labelImg标注数据目录结构如下(详情参见dataset/labelImg_dataset):

      labelImg_dataset
      ├── classes.txt
      ├── images(13).jpg
      ├── images(13).txt
      ├── images(3).jpg
      ├── images(3).txt
      ├── images4.jpg
      ├── images4.txt
      ├── images5.jpg
      ├── images5.txt
      ├── images6.jpg  # 注意这个是没有标注的
      ├── images7.jpg
      └── images7.txt
    
  • 转换

    python labelImg_2_yolov5.py --src_dir dataset/labelImg_dataset \
                                --out_dir dataset/labelImg_dataset_output \
                                --val_ratio 0.2 \
                                --have_test true \
                                --test_ratio 0.2
    • --src_dir:labelImg标注后所在目录
    • --out_dir: 转换之后的数据存放位置
    • --val_ratio:生成验证集占整个数据的比例,默认是0.2
    • --have_test:是否生成test部分数据,默认是True
    • --test_ratio:test数据整个数据百分比,默认是0.2
  • 转换后目录结构(详情参见dataset/labelImg_dataset_output):

    labelImg_dataset_output/
      ├── classes.txt
      ├── images
      │   ├── images(13).jpg
      │   ├── images(3).jpg
      │   ├── images4.jpg
      │   ├── images5.jpg
      │   └── images7.jpg
      ├── labels
      │   ├── images(13).txt
      │   ├── images(3).txt
      │   ├── images4.txt
      │   ├── images5.txt
      │   └── images7.txt
      ├── non_labels        # 这是没有标注图像的目录,自行决定如何处置
      │   └── images6.jpg
      ├── test.txt
      ├── train.txt
      └── val.txt
    
  • 可以进一步直接对dataset/labelImg_dataset_output目录作转COCO的转换

    python yolov5_2_coco.py --data_dir dataset/lablelImg_dataset_output

COCO格式数据 → labelImg

  • 将COCO格式数据一键转换为labelImg标注的yolo格式数据
  • COCO格式数据目录结构如下(详情参见:dataset/YOLOV5_COCO_format):
    YOLOV5_COCO_format
      ├── annotations
      │   ├── instances_train2017.json
      │   └── instances_val2017.json
      ├── train2017
      │   ├── 000000000001.jpg
      │   └── 000000000002.jpg  # 这个是背景图像
      └── val2017
          └── 000000000001.jpg
    
  • 转换
    python coco_2_labelImg.py --data_dir dataset/YOLOV5_COCO_format
    • --data_dir: COCO格式数据集所在目录
  • 转换后目录结构(详情参见:dataset/COCO_labelImg_format):
    COCO_labelImg_format
      ├── train
      │   ├── 000000000001.jpg
      │   ├── 000000000001.txt
      │   |-- 000000000002.jpg
      │   └── classes.txt
      └── val
          ├── 000000000001.jpg
          ├── 000000000001.txt
          └── classes.txt
    
  • 对转换之后的目录,可以直接用labelImg库直接打开,更改标注,具体命令如下:
    $ cd dataset/COCO_labelImg_format
    $ labelImg train train/classes.txt
    
    # or
    $ labelImg val val/classes.txt

YOLOV5格式数据 → COCO

  • 可以将一些背景图像加入到训练中,具体做法是:直接将背景图像放入backgroud_images目录即可。

  • 转换程序会自动扫描该目录,添加到训练集中,可以无缝集成后续YOLOX的训练。

  • YOLOV5训练格式目录结构(详情参见dataset/YOLOV5):

    YOLOV5
    ├── classes.txt
    ├── background_images  # 一般是和要检测的对象容易混淆的图像
    │   └── bg1.jpeg
    ├── images
    │   ├── images(13).jpg
    │   └── images(3).jpg
    ├── labels
    │   ├── images(13).txt
    │   └── images(3).txt
    ├── train.txt
    └── val.txt
    
  • train.txtval.txt中图像路径,以下两种均可:

    • 相对于根目录的路径
      dataset/YOLOV5/images/images(3).jpg
      
    • 相对于dataset/YOLOV5的相对路径
      images/images(3).jpg
      
  • 转换

    python yolov5_2_coco.py --data_dir dataset/YOLOV5 --mode_list train,val
    • --data_dir:整理好的数据集所在目录
    • --mode_list:指定生成的json,前提是要有对应的txt文件,可单独指定。(e.g. train,val,test
  • 转换后目录结构(详情参见dataset/YOLOV5_COCO_format):

    YOLOV5_COCO_format
    ├── annotations
    │   ├── instances_train2017.json
    │   └── instances_val2017.json
    ├── train2017
    │   ├── 000000000001.jpg
    │   └── 000000000002.jpg  # 这个是背景图像
    └── val2017
        └── 000000000001.jpg
    

YOLOV5 YAML描述文件 → COCO

  • YOLOV5 yaml 数据文件目录结构如下(详情参见dataset/YOLOV5_yaml):

    YOLOV5_yaml
    ├── images
    │   ├── train
    │   │   ├── images(13).jpg
    │   │   └── images(3).jpg
    │   └── val
    │       ├── images(13).jpg
    │       └── images(3).jpg
    ├── labels
    │   ├── train
    │   │   ├── images(13).txt
    │   │   └── images(3).txt
    │   └── val
    │       ├── images(13).txt
    │       └── images(3).txt
    └── sample.yaml
    
  • 转换

    python yolov5_yaml_2_coco.py --yaml_path dataset/YOLOV5_yaml/sample.yaml

darknet格式数据 → COCO

  • darknet训练数据目录结构(详情参见dataset/darknet):

    darknet
    ├── class.names
    ├── gen_config.data
    ├── gen_train.txt
    ├── gen_valid.txt
    └── images
        ├── train
        └── valid
    
  • 转换

    python darknet_2_coco.py --data_path dataset/darknet/gen_config.data

可视化COCO格式下图像

python coco_visual.py --vis_num 1 \
                    --json_path dataset/YOLOV5_COCO_format/annotations/instances_train2017.json \
                    --img_dir dataset/YOLOV5_COCO_format/train2017
  • --vis_num:指定要查看的图像索引
  • --json_path:查看图像的json文件路径
  • --img_dir: 查看图像所在的目录

COCO格式Object Instance示例

{
    "info": {
      "year": 2022,
      "version": "1.0",
      "description": "For object detection",
      "date_created": "2022"
    },
    "licenses":  [{
        "id": 1,
        "name": "Apache License v2.0",
        "url": "https://github.com/RapidAI/YOLO2COCO/LICENSE"
    }],
    "images": [{
        "date_captured": "2022",
        "file_name": "000000000001.jpg",
        "id": 1,
        "height": 224,
        "width": 224
    }, {
        "date_captured": "2022",
        "file_name": "000000000002.jpg",
        "id": 2,
        "height": 424,
        "width": 550
    }],
    "annotations": [{
        "segmentation": [[18.00, 2.99, 105.00, 2.99, 105.00, 89.00, 18.00, 89.00]],
        "area": 7482.011,
        "iscrowd": 0,
        "image_id": 1,  // 对应images中的id
        "bbox": [18.00, 2.99, 87.00, 86.00],  // [x, y, w, h]其中(x,y)是左上角的值,w,h是框的宽和高
        "category_id": 1,  // 对应categories中的ID
        "id": 1  // 唯一区分不同标注实例的编号
    }, {
        "segmentation": [
            [126.99, 3.99, 210.99, 3.99, 210.99, 88.99, 126.99, 88.99]
        ],
        "area": 7139.994,
        "iscrowd": 0,
        "image_id": 1,
        "bbox": [126.99, 3.99, 84.0, 84.99],
        "category_id": 1,
        "id": 2
    }],
    "categories": [{
        "supercategory": "stamp",
        "id": 1,
        "name": "stamp"
    }]
}

相关资料

More Repositories

1

RapidOCR

Awesome OCR multiple programing languages toolkits based on ONNXRuntime, OpenVION and PaddlePaddle. (将PaddleOCR模型做了转换,采用ONNXRuntime推理,速度很快)
Python
2,639
star
2

RapidASR

商用级开源语音自动识别程序库,开箱即用,全平台支持,中英文混合识别。A Cross-platform implementation of ASR inference. It's based on ONNXRuntime and FunASR. We provide a set of easier APIs to call ASR models.
C++
483
star
3

RapidLaTeXOCR

Formula recognition based on LaTeX-OCR and ONNXRuntime.
Python
266
star
4

Knowledge-QA-LLM

QA based on local knowledge and LLM.
Python
189
star
5

RapidStructure

版面分析 | 表格识别 | 文档方向分类
Python
177
star
6

RapidOcrOnnx

rapidocr onnx cpp
C++
146
star
7

TableStructureRec

整理目前开源的表格识别模型,完善前后处理,模型转换为ONNX
Python
130
star
8

RapidOCRPDF

Based on RapidOCR, extract the PDF content.
Python
119
star
9

RapidLayout

Analysis of Chinese and English layouts 中英文版面分析
Python
81
star
10

RapidOcrAndroidOnnx

C++
53
star
11

RapidOcrNcnn

RapidOCR ncnn 推理
C++
50
star
12

PaddleOCRModelConvert

Convert the model in PaddleOCR to ONNX format
Python
45
star
13

LLM-EXAM

大模型中文测试题库-民间版本
45
star
14

RapidTTS

A cross platform implementation of Text-to-Speech based on ONNXRuntime.
Python
32
star
15

OnnxruntimeBuilder

Onnxruntime Builder
Shell
31
star
16

RapidOCRCSharp

C#
28
star
17

OpenCVBuilder

OpenCV Custom Builder
Shell
22
star
18

Paddle2OnnxConvertor

Convert paddle model to onnx model
Python
20
star
19

RapidPunc

A library for adding punctuation into a text from ASR.
C++
17
star
20

RapidOcrAndroidOnnxCompose

opencv onnxruntime ocr android demo, jetpack compose + kotlin
Kotlin
13
star
21

RapidVoice

The engineering implementation of SenseVoice (from Alibaba)
8
star
22

RapidTable

源自PP-Structure的表格识别算法,模型转换为ONNX,推理引擎采用ONNXRuntime,部署简单,无内存泄露问题。
Python
8
star
23

RapidOcrOnnxJvm

RapidOcr onnx java kotlin jni test
Kotlin
7
star
24

RapidOcrAndroidNcnn

C++
6
star
25

RapidLayoutRecover

针对文档类图像,整合版面分析、文字识别、表格识别和公式识别结果,还原版面布局信息。
Python
5
star
26

keyframe_extractor

To extract key frames from a video.
Python
5
star
27

paraformer_simple

Python
4
star
28

LLM-DOC

大模型研究院资料馆
4
star
29

RapidOcrNcnnJvm

RapidOcr ncnn java kotlin jni
Kotlin
4
star
30

RapidAudioKit

It's for the repository of audio resampling tools
C
3
star
31

RapidImgUtil

Image processing library to add some new formats and other supports.
C++
2
star
32

RapidOcrNcnnLibTest

rapid ocr ncnn lib test
CMake
2
star
33

RapidOCRDocs

RapidOCR Document
HTML
2
star
34

VoiceCut

1
star
35

paddleocr2ncnn

Batchfile
1
star
36

RapidAIWebSite

HTML
1
star
37

RapidOcrOnnxLibTest

rapidocr onnx cpp lib test
CMake
1
star
38

RapidPix2Pix

Inference code based on the onnxruntime about pix2pix
Python
1
star