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

Owner
llt
Object detection, Time Series Forecasting
llt
👐OpenHands : Making Sign Language Recognition Accessible (WiP 🚧👷‍♂️🏗)

👐 OpenHands: Sign Language Recognition Library Making Sign Language Recognition Accessible Check the documentation on how to use the library: ReadThe

AI4Bhārat 69 Dec 12, 2022
Real-time LIDAR-based Urban Road and Sidewalk detection for Autonomous Vehicles 🚗

urban_road_filter: a real-time LIDAR-based urban road and sidewalk detection algorithm for autonomous vehicles Dependency ROS (tested with Kinetic and

JKK - Vehicle Industry Research Center 180 Dec 12, 2022
text_recognition_toolbox: The reimplementation of a series of classical scene text recognition papers with Pytorch in a uniform way.

text recognition toolbox 1. 项目介绍 该项目是基于pytorch深度学习框架,以统一的改写方式实现了以下6篇经典的文字识别论文,论文的详情如下。该项目会持续进行更新,欢迎大家提出问题以及对代码进行贡献。 模型 论文标题 发表年份 模型方法划分 CRNN 《An End-t

168 Dec 24, 2022
Here is the diagnostic tool for BMVC 2021 paper Diagnosing Errors in Video Relation Detectors.

Here is the diagnostic tool for BMVC 2021 paper Diagnosing Errors in Video Relation Detectors. We provide a tiny ground truth file demo_gt.json, and t

Shuo Chen 3 Dec 26, 2022
Example of a Quantum LSTM

Example of a Quantum LSTM

Riccardo Di Sipio 36 Oct 31, 2022
A scikit-learn compatible neural network library that wraps PyTorch

A scikit-learn compatible neural network library that wraps PyTorch. Resources Documentation Source Code Examples To see more elaborate examples, look

4.9k Dec 31, 2022
Python scripts for performing stereo depth estimation using the MobileStereoNet model in Tensorflow Lite.

TFLite-MobileStereoNet Python scripts for performing stereo depth estimation using the MobileStereoNet model in Tensorflow Lite. Stereo depth estimati

Ibai Gorordo 4 Feb 14, 2022
Code for Environment Inference for Invariant Learning (ICML 2020 UDL Workshop Paper)

Environment Inference for Invariant Learning This code accompanies the paper Environment Inference for Invariant Learning, which appears at ICML 2021.

Elliot Creager 40 Dec 09, 2022
PyTorch framework, for reproducing experiments from the paper Implicit Regularization in Hierarchical Tensor Factorization and Deep Convolutional Neural Networks

Implicit Regularization in Hierarchical Tensor Factorization and Deep Convolutional Neural Networks. Code, based on the PyTorch framework, for reprodu

Asaf 3 Dec 27, 2022
Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks

Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks This repository contains a TensorFlow implementation of "

Jingwei Zheng 5 Jan 08, 2023
CUda Matrix Multiply library.

cumm CUda Matrix Multiply library. cumm is developed during learning of CUTLASS, which use too much c++ template and make code unmaintainable. So I de

49 Dec 27, 2022
Official code release for "Learned Spatial Representations for Few-shot Talking-Head Synthesis" ICCV 2021

Official code release for "Learned Spatial Representations for Few-shot Talking-Head Synthesis" ICCV 2021

Moustafa Meshry 16 Oct 05, 2022
This repository contains the implementation of Deep Detail Enhancment for Any Garment proposed in Eurographics 2021

Deep-Detail-Enhancement-for-Any-Garment Introduction This repository contains the implementation of Deep Detail Enhancment for Any Garment proposed in

40 Dec 13, 2022
A deep learning network built with TensorFlow and Keras to classify gender and estimate age.

Convolutional Neural Network (CNN). This repository contains a source code of a deep learning network built with TensorFlow and Keras to classify gend

Pawel Dziemiach 1 Dec 18, 2021
YOLOv5 🚀 is a family of object detection architectures and models pretrained on the COCO dataset

YOLOv5 🚀 is a family of object detection architectures and models pretrained on the COCO dataset, and represents Ultralytics open-source research int

阿才 73 Dec 16, 2022
Class-Attentive Diffusion Network for Semi-Supervised Classification [AAAI'21] (official implementation)

Class-Attentive Diffusion Network for Semi-Supervised Classification Official Implementation of AAAI 2021 paper Class-Attentive Diffusion Network for

Jongin Lim 7 Sep 20, 2022
This repository is for the preprint "A generative nonparametric Bayesian model for whole genomes"

BEAR Overview This repository contains code associated with the preprint A generative nonparametric Bayesian model for whole genomes (2021), which pro

Debora Marks Lab 10 Sep 18, 2022
Resources related to EMNLP 2021 paper "FAME: Feature-Based Adversarial Meta-Embeddings for Robust Input Representations"

FAME: Feature-based Adversarial Meta-Embeddings This is the companion code for the experiments reported in the paper "FAME: Feature-Based Adversarial

Bosch Research 11 Nov 27, 2022
A PyTorch implementation for our paper "Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation".

Dual-Contrastive-Learning A PyTorch implementation for our paper "Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation". Y

hoshi-hiyouga 85 Dec 26, 2022
Breast Cancer Classification Model is applied on a different dataset

Breast Cancer Classification Model is applied on a different dataset

1 Feb 04, 2022