Automatic labeling, conversion of different data set formats, sample size statistics, model cascade

Overview

Simple Gadget Collection for Object Detection Tasks

  • Automatic image annotation
  • Conversion between different annotation formats
  • Obtain statistical information about your dataset

This is a simple collection of gadgets for regular object detection tasks. You can also modify it yourself to implement your ideas. It is very simple to use, you just need to copy the python file you need to use, and specify the relevant parameters, and execute it. Please read the following tutorial carefully before using it.

1. Automatic image annotation:

auto_annotate_mmdetect.py
This tool is to help you complete a large number of labeling tasks quickly. It is based on the object detection model trained by mmdetection.
Usuage:
Step1: you need to use mmdetection and a small amount of labeled data (about 200~300 images) to train to get a rough object detection model(e.g. Faster-RCNN: faster_rcnn_r50_fpn_1x_coco.py). If you don't know how to use mmdetection to train a object detection model, I strongly suggest you read the tutorial on mmdetection first.
Step2: use auto_annotate_mmdetect.py to mark the remaining large amount of unmarked data and generate a VOC format (xml) file. Before that, you need to modify some places to specify the name of the annotation object and the place where the annotation file is saved.

files_path = '../project/mmdetection/data/image'              # The path of the image folder to be annotated  
img_save_path = './results'                                   # The path of the annotated images to be saved  
xml_save_path = './Annotations'                               # The path of the image annotation files (xml) to be saved  
cfg = './faster_rcnn_r50_fpn_1x_coco.py'                      # Your model configure file (mmdetection)  
wgt = './epoch_12.pth'                                        # Your model weight file  
device = 'cuda:0'                                             # Use GPU  
class_dic = {'0': 'cat',
             '1': 'dog',  
             '2': 'rabbit',  
             '3': 'mouse'}                                    # Class ID --> Class name  

Step3: auto_annotate_mmdetect.py, which will automatically use the model you just trained to generate the corresponding annotation files(xml).
Step4: you can use labelImg to manually correct the automatically generated files.

2.Conversion between different annotation formats:

2.1 PASCAL VOC-->COCO:

voc2coco.py
The annotation file format generated using labelImg is usually PASCAL VOC (xml) or YOLO(txt). When using many model training suites (e.g. mmdetection), you need to convert the xml files to COCO(json).
Usuage:
Step1: copy voc2coco.py to VOC dataset folder that you are going to transfer (as shown below).

Before:
dataset_VOC
  ├─ImageSets
  │  └─Main
  │     ├─train.txt
  │     ├─val.txt
  │     └─trainval.txt
  ├─Annotations    <--xml files are put there
  ├─JPEGImages     <--images are put there
  └─voc2coco.py    <--you should put it here

Step2: excute voc2coco.py. The images will be automatically copied to the specified folder. You only need to change the name of the dataset manually.

After:
dataset_COCO   <--You only need to change the name of the dataset manually
  ├─train     <--images for training are copied there
  ├─val       <--images for valuation are copied there
  ├─train.json
  └─val.json

By the way, it will automatically count information about the kinds your dataset contains and the number of its instances.(like this ↓)

=======Statistic Details===========  
Class Name: green_net, Instances: 119  
Class Name: obj, Instances: 522  
Class Name: kite, Instances: 152  
===================================  

========Create train.json DONE========  
Foud 3 categories: dict_keys(['obj', 'kite', 'green_net']) --> your predefine categories 3: dict_keys(['green_net', 'obj', 'kite'])  
Category: id --> {'green_net': 783, 'obj': 793, 'kite': 792}  
=====================================  

========Create val.json DONE========  
Foud 3 categories: dict_keys(['obj', 'kite', 'green_net']) --> your predefine categories 3: dict_keys(['green_net', 'obj', 'kite'])  
Category: id --> {'green_net': 783, 'obj': 793, 'kite': 792}  
=====================================

========Coco Dataset Details========  
Training set size: 516  
Valuation set size: 130  

2.2 COCO-->YOLO:

coco2yolov5.py This tool is used to solve the problem of converting COCO dataset format (json) to YOLO format (txt).
Usuage:
Step1: copy coco2yolov5.py to the coco dataset folder that you are going to transfer. (As show below↓)

Before:
dataset_coco
  ├─train.json        <--annotation json file (for training)
  ├─val.json          <--annotation json file (for valuation)
  ├─train             <--images are saved here (for training)
  ├─val               <--images are saved here (for valuation)
  └─coco2yolov5.py    <--you should put it here

Step2: specify the dataset name in coco2yolov5.py.

dataset_name = 'dataset'                  # specify your dataset name
dataset_name = dataset_name + '_yolo'

Step3: excute coco2yolov5.py.

After:
dataset_yolo
├─train┬images       <--images are saved here (for training)
│       └labels      <--annotation txt file (for training)
│
└─val┬─images        <--images are saved here (for valuation)
       └─labels      <--annotation txt file (for valuation)

3. Obtain statistical information about your dataset:

3.1 Simple statistical information:

These tools provide statistical methods for different formats of annotation files. You can use the statistical tools to quickly understand the percentage of each sample and determine whether the samples are balanced with each other, providing useful information for your next training and fine-tuning.

xml_cls_stat.py and json_cls_stat.py to obtain the statistical information of the annotation file in VOC and COCO format respectively. The usage method is very simple, you need to copy xml_cls_stat.py or json_cls_stat.py to your VOC or COCO data set folder.
It should be noted that the annotation files and images in the VOC format are stored uniformly, and xml_cls_stat.py counts the information of the entire dataset. And to use json_cls_stat.py you need to specify whether to count train or val.
json = json.load(open('train.json')) # Specify train.json
Then execute it, you can get statistics of all categories and the number of instances. (As show below↓)

=======Statistic Details===========
Class Name: DC, Class ID: 2455, Instances: 865
Class Name: HC, Class ID: 2448, Instances: 383
Class Name: WJ, Class ID: 2449, Instances: 696

3.2 Find pictures that contain the specified class

xml_find_picture.py and json_find_picture.py. The usage is exactly the same and very simple, you only need to copy it to the VOC data set folder. Specify the name of the category you need to find, specified_name ='WJ'
Finally, execute it.
The program will print out the file name containing the specified class, and show how many pictures in total contain the class you specified. (As show below↓)

···
machinery561.xml
machinery394.xml
machinery394.xml
machinery225.xml
machinery084.xml
There are 881 pictures contain specified category, (CateName=WJ)

4. Modify your dataset:

NOTE: I still recommend that you should back up your data before proceeding to avoid tragedy.

4.1 Remove specified class

xml_cls_del.py
Sometimes you will need to delete some special classes, and the workload of manually deleting specified classes is very huge. When you encounter this situation, you can use this tool to delete certain classes you don't need.
Copy xml_cls_del.py to your folder, specify the class you want to delete, and finally execute it.
Don't worry, the program will automatically create a folder called ‘New_Annotation’ to store these modified annotation files, and your original annotation files will not be affected in any way.

specified_class_name = 'WJ'  # Specify the name of the class to be deleted  

Finally, the program will tell you how many instances have been deleted. (As show below↓)

There are 648 objects have been removed.

4.2 Modify the name of the specified class

xml_cls_namechange.py or json_cls_namechange.py
The tools of the VOC (xml) version and COCO (json) version are provided here, and they are used in the same way. When you need to modify the name of a certain class or merge certain classes, you can use it to achieve. Don't worry, the program will automatically create a folder called ‘New_Annotation’ to store these modified annotation files, and your original annotation files will not be affected in any way.
Like other tools, you only need to copy xml_cls_namechange.py or json_cls_namechange.py to your dataset folder, and specify your json file save path:

json_path = './train.json'	    	#json file path before modification
json_save_path = './train2.json'	#Modified json file save path 

specify the name of the class you want to modify, and then execute it.

specified_cls_name = "A" 	  	    #Class name to be modified 
new_name = "AA"	    	 	          #New class name 

5. Simple image data enhancement:

simple_data_enhancement.py Specify the folder that needs data enhancement, then select the enhancement method you need to use according to your needs, and finally execute it.
The tool provides 6 common methods: rotate, flip, brighten, darken, salt and pepper noise, and Gaussian noise. For unneeded methods, just turn their code into comments.
file_dir = r'../data/img/' # Specify the folder that needs data enhancement

6. Use models for inference (prediction):

infer_by_folder_mmdetection.py
mmdetection officially provides scripts and commands for model inference, but they need to use command line operations. More often you may want to make model inferences according to your own ideas. For example, when you deploy a model, your model needs to receive images from the network, or you need to cascade two models to use in some situations It is not very convenient to use the command line according to the official tutorial. Here is a simple inference script for you.
I have provided a simple example. You can put pictures in a folder, and then the program will traverse the pictures in the folder, get the inference result of the model and save it in another folder. It is also very easy to transform, you can transform it into anything you need according to actual production needs, such as cascading.

7. Cascade of models:

Examples of practical application of model cascade infer_paddle_2stages.py infer_mmdet_2stages.py

You might also like...
CFNet: Cascade and Fused Cost Volume for Robust Stereo Matching(CVPR2021)

CFNet(CVPR 2021) This is the implementation of the paper CFNet: Cascade and Fused Cost Volume for Robust Stereo Matching, CVPR 2021, Zhelun Shen, Yuch

3D cascade RCNN for object detection on point cloud
3D cascade RCNN for object detection on point cloud

3D Cascade RCNN This is the implementation of 3D Cascade RCNN: High Quality Object Detection in Point Clouds. We designed a 3D object detection model

Real-CUGAN - Real Cascade U-Nets for Anime Image Super Resolution

Real Cascade U-Nets for Anime Image Super Resolution 中文 | English 🔥 Real-CUGAN

Image transformations designed for Scene Text Recognition (STR) data augmentation. Published at ICCV 2021 Workshop on Interactive Labeling and Data Augmentation for Vision.

Data Augmentation for Scene Text Recognition (ICCV 2021 Workshop) (Pronounced as "strog") Paper Arxiv Why it matters? Scene Text Recognition (STR) req

Empower Sequence Labeling with Task-Aware Language Model
Empower Sequence Labeling with Task-Aware Language Model

LM-LSTM-CRF Check Our New NER Toolkit 🚀 🚀 🚀 Inference: LightNER: inference w. models pre-trained / trained w. any following tools, efficiently. Tra

DiffQ performs differentiable quantization using pseudo quantization noise. It can automatically tune the number of bits used per weight or group of weights, in order to achieve a given trade-off between model size and accuracy.

Differentiable Model Compression via Pseudo Quantization Noise DiffQ performs differentiable quantization using pseudo quantization noise. It can auto

Implementation of Kaneko et al.'s MaskCycleGAN-VC model for non-parallel voice conversion.
Implementation of Kaneko et al.'s MaskCycleGAN-VC model for non-parallel voice conversion.

MaskCycleGAN-VC Unofficial PyTorch implementation of Kaneko et al.'s MaskCycleGAN-VC (2021) for non-parallel voice conversion. MaskCycleGAN-VC is the

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.

Core ML Tools Use coremltools to convert machine learning models from third-party libraries to the Core ML format. The Python package contains the sup

Automatic self-diagnosis program (python required)Automatic self-diagnosis program (python required)

auto-self-checker 자동으로 자가진단 해주는 프로그램(python 필요) 중요 이 프로그램이 실행될때에는 절대로 마우스포인터를 움직이거나 키보드를 건드리면 안된다(화면인식, 마우스포인터로 직접 클릭) 사용법 프로그램을 구동할 폴더 내의 cmd창에서 pip

Owner
llt
Object detection, Time Series Forecasting
llt
🍅🍅🍅YOLOv5-Lite: lighter, faster and easier to deploy. Evolved from yolov5 and the size of model is only 1.7M (int8) and 3.3M (fp16). It can reach 10+ FPS on the Raspberry Pi 4B when the input size is 320×320~

YOLOv5-Lite:lighter, faster and easier to deploy Perform a series of ablation experiments on yolov5 to make it lighter (smaller Flops, lower memory, a

pogg 1.5k Jan 5, 2023
Automatically download the cwru data set, and then divide it into training data set and test data set

Automatically download the cwru data set, and then divide it into training data set and test data set.自动下载cwru数据集,然后分训练数据集和测试数据集

null 6 Jun 27, 2022
A very simple tool for situations where optimization with onnx-simplifier would exceed the Protocol Buffers upper file size limit of 2GB, or simply to separate onnx files to any size you want.

sne4onnx A very simple tool for situations where optimization with onnx-simplifier would exceed the Protocol Buffers upper file size limit of 2GB, or

Katsuya Hyodo 10 Aug 30, 2022
Matlab Python Heuristic Battery Opt - SMOP conversion and manual conversion

SMOP is Small Matlab and Octave to Python compiler. SMOP translates matlab to py

Tom Xu 1 Jan 12, 2022
Yolox-bytetrack-sample - Python sample of MOT (Multiple Object Tracking) using YOLOX and ByteTrack

yolox-bytetrack-sample YOLOXとByteTrackを用いたMOT(Multiple Object Tracking)のPythonサン

KazuhitoTakahashi 12 Nov 9, 2022
Combining Automatic Labelers and Expert Annotations for Accurate Radiology Report Labeling Using BERT

CheXbert: Combining Automatic Labelers and Expert Annotations for Accurate Radiology Report Labeling Using BERT CheXbert is an accurate, automated dee

Stanford Machine Learning Group 51 Dec 8, 2022
Voxel Set Transformer: A Set-to-Set Approach to 3D Object Detection from Point Clouds (CVPR 2022)

Voxel Set Transformer: A Set-to-Set Approach to 3D Object Detection from Point Clouds (CVPR2022)[paper] Authors: Chenhang He, Ruihuang Li, Shuai Li, L

Billy HE 141 Dec 30, 2022
PRTR: Pose Recognition with Cascade Transformers

PRTR: Pose Recognition with Cascade Transformers Introduction This repository is the official implementation for Pose Recognition with Cascade Transfo

mlpc-ucsd 133 Dec 30, 2022
Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The original code is written in keras.

CasRel-pytorch-reimplement Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The o

longlongman 170 Dec 1, 2022
一个目标检测的通用框架(不需要cuda编译),支持Yolo全系列(v2~v5)、EfficientDet、RetinaNet、Cascade-RCNN等SOTA网络。

一个目标检测的通用框架(不需要cuda编译),支持Yolo全系列(v2~v5)、EfficientDet、RetinaNet、Cascade-RCNN等SOTA网络。

Haoyu Xu 203 Jan 3, 2023