Giter VIP home page Giter VIP logo

autoannoter's Introduction

autoAnnoter


autoAnnoter: Its a tool to auto annotate data using a exisiting model

Auto annotate any class ๐Ÿš€ New Update (17-08-2023)

๐Ÿฅณ Auto Annotate using OWL-ViT Model

We can auto annotate any class on our data using new OWL-ViT model.
No need of any pre-trained or any custom model to auto-annotate.

About OWL-ViT

OWL-ViT is an open-vocabulary object detector. It means that it can detect objects in images based on free-text queries without the need to fine-tune the model on labeled datasets.

Updates

Show
  • (12-06-2023) Grounding DINO ๐Ÿฆ• auto annotate any class

  • (01-06-2023) YOLO-NAS Auto Annotation

    • Auto Annotate using YOLO-NAS Model
  • (25-04-2023): We can remove any classes from auto annotation. So that we can create new set of dataset using existing model. Example:

    • If we need to create a people detection model. We can create new dataset from existing COCO model.
    • If I need to create a dataset to train a model to detect helmet, shoe and person. But I can't annotate big dataset. But I have a model to detect Helmet, Person and other classes as well. But I can use this new feature (Remove Classes from Auto Annotation) only annotate Helmet and Person. This will reduce 2/3 of my work. After this I only need to annotate Shoe.
  • (24-04-2023): Added visualization tool and fixed issue with XML to TXT conversion.

    • xml_to_txt.py (Updated)
      • Fixed issue with, when unexpected format of xml annotation came, position of xmax and ymin maybe change, now it can handle any bounding box format.
    • Added XML and TXT annotation visualization tool
      • vis_xml.py : to visulise xml (Pascal VOC) annotation format
      • vis_txt.py : to visulise txt (YOLO) annotation format
  • (03-02-2023) YOLOv8 Auto Annotation

    • Auto Annotate using YOLOv8 Model
  • (02-11-2022) Added tools to this repository, that can help you to setup your Dataset for the Training.

    • partition_dataset.py : Partition your Dataset (XML & TXT & Images) into Train and Test in ratio
    • txt_to_xml.py : Convert your TXT Annotation files into XML Format
    • xml_to_txt.py : Convert your XML Annotation files into TXT Format
    • xml_neg_annotation.py : Annoatate your Negative Dataset
    • find_oneClass_from_xml.py : To filter your PASCAL VOC annotaion XML file based on class name

Clone this GitHub Repository

git clone https://github.com/naseemap47/autoAnnoter.git

Install Dependencies

Recommended:

conda create -n auto python=3.9 -y
conda activate auto
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch -y
pip install -r requirements.txt

OR

cd autoAnnoter/
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
pip install -r requirements.txt

Zero-shot object detection

1. Grounding DINO ๐Ÿฆ•

Grounding DINO is text to detection model. So we need to give text prompt that correspond to respective class.

2. OWL-ViT (Recommended)

OWL-ViT is an open-vocabulary object detector. It means that it can detect objects in images based on free-text queries without the need to fine-tune the model on labeled datasets..

Auto annotate any class

To do this, we needs to create prompt.json

JSON keys should be text prompt to Grounding DINO model.
But the values for the each keys should be class names for that detection.

Example:

Here I need to train one custom model that can predict high quality cap and low quality cap.
So for this I give my Grounding DINO/OWL-ViT text prompt as red cap and yellow caps, to annotate my high quality cap and low quality cap classes.
I give this example to show you that, some times we need to give Grounding DINO/OWL-ViT text prompt as more elaborate way, like my example.

out11

{
    "red caps": "high quality cap",
    "yellow caps": "low quality cap"
}

This approch we can use when the object is same, but have different feature like color.

1. OWL-ViT (Recommended)

Args

-i, --dataset: path to dataset/dir
-p, --prompt: path to prompt.json
-bt, --box_thld: bounding box Threshold

To auto-annotate OWL-ViT model, we need to give text prompt that correspond to respective class.

Example:

python3 owlvit.py --dataset images/ --prompt prompt.json

2. Grounding DINO ๐Ÿฆ•

Args

-i, --dataset: path to dataset/dir
-p, --prompt: path to prompt.json
-bt, --box_thld: Box Threshold
-tt, --txt_thld: text threshold

To auto-annotate Grounding DINO model, we need to give text prompt that correspond to respective class.

Example:

python3 dino.py --dataset images/ --prompt prompt.json

2. ONNX Model

Args

-x, --xml: to annotate in XML format
-t, --txt: to annotate in (.txt) format
-i, --dataset: path to dataset/dir
-c, --classes: path to classes.txt
-m, --model: path to ONNX model
-s, --size: Size of image used to train the model
-conf, --confidence: Model detection Confidence (0<confidence<1)
-r, --remove: List of classes need to remove
-k, --keep: List of classes need to keep

Example:

To .xml

python3 autoAnnot.py --xml --dataset images/ --classes classes.txt \
                     --model models/model.onnx --size 224 --confidence 0.75

To .txt

python3 autoAnnot.py --txt --dataset images/ --classes classes.txt \
                     --model models/model.onnx --size 224 --confidence 0.75

To Remove classes from auto-annotation

python3 autoAnnot.py --txt --dataset images/ --classes classes.txt \
                     --model models/model.onnx --size 224 --confidence 0.75 \
                     --remove 'person' 'car

To Keep classes from auto-annotation

python3 autoAnnot.py --txt --dataset images/ --classes classes.txt \
                     --model models/model.onnx --size 224 --confidence 0.75 \
                     --keep 'person' 'car

3. YOLO Model

Args

-i, --dataset: path to dataset/dir
-mt, --model_type: Choose YOLO Model "YOLOv7 or YOLOv8"
-m, --model: path to best.pt (YOLO) model
-conf, --confidence: Model detection Confidence (0<confidence<1)
-r, --remove: List of classes need to remove
-k, --keep: List of classes need to keep

for YOLO-NAS Model
-t, --type: Choose YOLO-NAS model type
example: yolo_nas_s, yolo_nas_m, yolo_nas_l
-n, --num: number of classes that model trained on

Examples:

1. YOLOv7 Model

python3 autoAnotYolo.py --dataset dataset/images --model_type yolov7 \
                        --model runs/train/weights/best.pt --confidence 0.8
  • To Remove classes from auto-annotation
python3 autoAnotYolo.py --dataset dataset/images --model_type yolov7 \
                        --model runs/train/weights/best.pt --confidence 0.8 \
                        --remove 'bus'
  • To Keep classes from auto-annotation
python3 autoAnotYolo.py --dataset dataset/images --model_type yolov7 \
                        --model runs/train/weights/best.pt --confidence 0.8 \
                        --keep 'bus'

2. YOLOv8 Model

python3 autoAnotYolo.py --dataset dataset/images --model_type yolov8 \
                        --model runs/train/weights/best.pt --confidence 0.8
  • To Remove classes from auto-annotation
python3 autoAnotYolo.py --dataset dataset/images --model_type yolov8 \
                        --model runs/train/weights/best.pt --confidence 0.8 \
                        --remove 'elephant' 'cat' 'bear'
  • To Keep classes from auto-annotation
python3 autoAnotYolo.py --dataset dataset/images --model_type yolov8 \
                        --model runs/train/weights/best.pt --confidence 0.8 \
                        --keep 'cat'

3. YOLO-NAS Model

Custom Model

python3 autoAnotYolo.py --dataset dataset/images --model_type yolonas \
                        --model runs/train/weights/best.pt --type yolo_nas_s \
                        --num 8 --confidence 0.8

COCO Model

python3 autoAnotYolo.py --dataset dataset/images --model_type yolonas \
                        --model coco --type yolo_nas_s \
                        --confidence 0.8
  • To Remove classes from auto-annotation
python3 autoAnotYolo.py --dataset dataset/images --model_type yolonas \
                        --model runs/train/weights/best.pt --type yolo_nas_s \
                        --num 80 --confidence 0.8 \
                        --remove 'car'
  • To Keep classes from auto-annotation
python3 autoAnotYolo.py --dataset dataset/images --model_type yolonas \
                        --model runs/train/weights/best.pt --type yolo_nas_s \
                        --num 32 --confidence 0.8 \
                        --keep 'car'

๐Ÿ› ๏ธ Tools

1. partition_dataset.py:

Partition your Dataset (XML & TXT & Images) into Train and Test in ratio

Args

-x, --xml : To partition XML files
-t, --txt : To partition TXT files
-i, --imageDir : path to image Dir, it should contain both images and Annotation files (XML or TXT)
-o, --outputDir : path to save Train and Test Dir, If not given - it will save inside image Dir
-r, --ratio : Ratio to partition Dataset into Train and Test (0 < ratio < 1)

Example Image Dir:

โ”œโ”€โ”€ path_to/images
โ”‚   โ”œโ”€โ”€ 1.jpg
โ”‚   โ”œโ”€โ”€ 1.xml
โ”‚   โ”œโ”€โ”€ 2.jpeg
โ”‚   โ”œโ”€โ”€ 2.xml
โ”‚   โ”œโ”€โ”€ ...
.   .
.   .
โ”œโ”€โ”€ path_to/images
โ”‚   โ”œโ”€โ”€ 1.jpeg
โ”‚   โ”œโ”€โ”€ 1.txt
โ”‚   โ”œโ”€โ”€ 2.jpg
โ”‚   โ”œโ”€โ”€ 2.txt
โ”‚   โ”œโ”€โ”€ ...
.   .
.   .

Example:

# XML
python3 tools/partition_dataset.py -x -i path_to/images -r 0.1

# TXT
python3 tools/partition_dataset.py -t -i path_to/images -r 0.1

2. txt_to_xml.py:

Convert your TXT Annotation files into XML Format

Args

-i, --image : path to image/dir
-t, --txt : path to txt/dir
-c, --classes : path to classes.txt

classes.txt Example:

car
person
apple
....

Example:

python3 tools/txt_to_xml.py -i path_to/imageDir -t path_to/txt_Dir -c path_to/classes.txt

3. xml_to_txt.py:

Convert your XML Annotation files into TXT Format

Args

-i, --image : path to image/dir
-x, --xml : path to xml/dir
-c, --classes : path to classes.txt

classes.txt Example:

car
person
apple
....

Example:

python3 tools/xml_to_txt.py -i path_to/imageDir -x path_to/xml_Dir -c path_to/classes.txt

4. xml_neg_annotation.py:

Annoatate your Negative Dataset

Args

-i, --dataset : path to negative dataset
-o, --save : path to save Dir, if not exist it will create

Example:

python3 tools/xml_neg_annotation.py -i path_to/negDir -o path_to/saveDir

5. find_oneClass_from_xml.py:

To filter your PASCAL VOC annotaion XML file based on class name

Args

-i, --dataset : path to negative dataset
-o, --save : path to save Dir
-n, --name : name of class, that wants filter

Example:

python3 tools/find_oneClass_from_xml.py -i path_to/dataset -o path_to/saveDir -n 'class_name'

6. vis_xml.py:

to visulise xml (Pascal VOC) annotation format

Args

-i, --img : path to image file
-x, --xml : path to xml file
-c, --classes : path to classes.txt
--save : to save annotated image

Example:

python3 tools/vis_xml.py -i path_to/image -x path_to/xml -c path_to_classes.txt

# to save image
python3 tools/vis_xml.py -i path_to/image -x path_to/xml -c path_to_classes.txt --save

7. vis_txt.py:

to visulise txt (YOLO) annotation format

Args

-i, --img : path to image file
-t, --txt : path to txt file
-c, --classes : path to classes.txt
--save : to save annotated image

Example:

python3 tools/vis_txt.py -i path_to/image -t path_to/txt -c path_to_classes.txt

# to save image
python3 tools/vis_txt.py -i path_to/image -t path_to/txt -c path_to_classes.txt --save

8. create_yolo.py:

to convert mixed images & labels into respective directory of images and labels

Args

-i, --data : path to image/dir/data

Example:

python3 tools/create_yolo.py -i path_to/data Dir

9. yolo_to_kitti.py:

to convert YOLO annotations (.txt) to KITTI format

Args

-i, --img : path to image file
-t, --txt : path to txt file
-c, --classes : path to classes.txt

Example:

python3 tools/yolo_to_kitti.py -i path_to/image -t path_to/txt -c path_to_classes.txt

10. yolo_to_json.py:

Convert your TXT (YOLO) Annotation files into COCO JSON Format

Args

-i, --image : path to image/dir
-t, --txt : path to txt/dir
-c, --classes : path to classes.txt

classes.txt Example:

car
person
apple
....

Example:

python3 tools/yolo_to_json.py -i path_to/imageDir -t path_to/txt_Dir -c path_to/classes.txt

autoannoter's People

Contributors

naseemap47 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.