Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding WordNet, CLIP annotator, advanced configuration, Docker image, improved README #49

Merged
merged 22 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/gar-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Reference: https://gist.github.com/joeyslalom/3a3b4783ea9f2e7fa3493c13bcf68e0a

name: Deploy single image to GAR (Google Artifact Registry)

on:
release:
types: [created]
env:
PROJECT_ID: easyml-394818
GAR_LOCATION: us-central1

jobs:
push-store:
name: Push single images
runs-on: buildjet-4vcpu-ubuntu-2204

steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main

- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/[email protected]'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
token_format: 'access_token'

- uses: 'docker/login-action@v1'
name: 'Docker login'
with:
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev'
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.access_token }}'

- name: 'Build Inventory Image'
working-directory: ./images/${{github.repository_name}}
run: |
docker build --build-arg GITHUB_TOKEN=${{secrets.GHCR_PAT}} . --tag $GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/internal/${{github.repository_name}}:latest --tag $GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/internal/${{github.repository_name}}:${{ github.event.release.tag_name }}
docker push $GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/internal/${{github.repository_name}} --all-tags
32 changes: 32 additions & 0 deletions .github/workflows/ghcr-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Docker Build and Publish

on:
release:
types: [created]

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Docker Build
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.repository_name }}:${{ github.event.release.tag_name }}
ghcr.io/${{ github.repository_owner }}/${{ github.repository_name }}:latest
env:
DOCKER_BUILDKIT: 1
DOCKER_USERNAME: ${{ github.repository_owner }}
DOCKER_PASSWORD: ${{ secrets.GHCR_PAT }}

- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## define a base image
FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-runtime

## set working directory
WORKDIR /app

## instal
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
RUN apt-get install -y git
RUN git clone https://github.com/luxonis/datadreamer.git -b main

RUN cd datadreamer && pip install .

## define image execution
ENTRYPOINT ["datadreamer"]
155 changes: 99 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

![DataDreamer examples](https://raw.githubusercontent.com/luxonis/datadreamer/main/images/grid_image_3x2_generated_dataset.jpg)

## Quickstart
<a name="quickstart"></a>

## 🚀 Quickstart

To generate your dataset with custom classes, you need to execute only two commands:

Expand All @@ -16,9 +18,11 @@ pip install datadreamer
datadreamer --class_names person moon robot
```

## Overview
<a name ="overview"></a>

## 🌟 Overview

<img src='images/datadreamer_scheme.gif' align="center">
<img src='https://raw.githubusercontent.com/luxonis/datadreamer/main/images/datadreamer_scheme.gif' align="center">

`DataDreamer` is an advanced toolkit engineered to facilitate the development of edge AI models, irrespective of initial data availability. Distinctive features of DataDreamer include:

Expand All @@ -28,26 +32,27 @@ datadreamer --class_names person moon robot

- **Efficient and Potent Models**: The primary objective of `DataDreamer` is to enable the creation of compact models that are both size-efficient for integration into any device and robust in performance for specialized tasks.

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Hardware Requirements](#hardware-requirements)
- [Usage](#usage)
- [Main Parameters](#main-parameters)
- [Additional Parameters](#additional-parameters)
- [Available models](#available-models)
- [Example](#example)
- [Output](#output)
- [Annotations Format](#annotations-format)
- [Note](#note)
- [Limitations](#limitations)
- [License](#license)
- [Acknowledgements](#acknowledgements)
## 📜 Table of contents

- [🚀 Quickstart](#quickstart)
- [🌟 Overview](#overview)
- [🛠️ Features](#features)
- [💻 Installation](#installation)
- [⚙️ Hardware Requirements](#hardware-requirements)
- [📋 Usage](#usage)
- [🎯 Main Parameters](#main-parameters)
- [🔧 Additional Parameters](#additional-parameters)
- [🤖 Available Models](#available-models)
- [💡 Example](#example)
- [📦 Output](#output)
- [📝 Annotations Format](#annotations-format)
- [⚠️ Limitations](#limitations)
- [📄 License](#license)
- [🙏 Acknowledgements](#acknowledgements)

<a name="features"></a>

## Features
## 🛠️ Features

- **Prompt Generation**: Automate the creation of image prompts using powerful language models.

Expand All @@ -57,27 +62,64 @@ datadreamer --class_names person moon robot

- **Image Generation**: Generate synthetic datasets with state-of-the-art generative models.

<img src="https://raw.githubusercontent.com/luxonis/datadreamer/main/images/generated_image.jpg" width="512">

- **Dataset Annotation**: Leverage foundation models to label datasets automatically.

<img src="https://raw.githubusercontent.com/luxonis/datadreamer/main/images/annotated_image.jpg" width="512">

- **Edge Model Training**: Train efficient small-scale neural networks for edge deployment. (not part of this library)

<img src="https://raw.githubusercontent.com/luxonis/datadreamer/main/images/generated_image.jpg" width="400"><img src="https://raw.githubusercontent.com/luxonis/datadreamer/main/images/annotated_image.jpg" width="400">

<a name="installation"></a>

## Installation
## 💻 Installation

There are two ways to install the `datadreamer` library:

**Using pip**:

To install with pip:

```bash
pip install datadreamer
```

**Using Docker (for Linux/Windows)**:

Pull Docker Image from GHCR:

```bash
docker pull ghcr.io/luxonis/datadreamer:latest
```

Or build Docker Image from source:

```bash
# Clone the repository
git clone https://github.com/luxonis/datadreamer.git
cd datadreamer

# Build Docker Image
docker build -t datadreamer .
```

**Run Docker Container (assuming it's GHCR image, otherwise replace `ghcr.io/luxonis/datadreamer:latest` with `datadreamer`)**

Run on CPU:

```bash
docker run --rm -v "$(pwd):/app" ghcr.io/luxonis/datadreamer:latest --save_dir generated_dataset --device cpu
```

Run on GPU, make sure to have nvidia-docker installed:

```bash
docker run --rm --gpus all -v "$(pwd):/app" ghcr.io/luxonis/datadreamer:latest --save_dir generated_dataset --device cuda
```

These commands mount the current directory ($(pwd)) to the /app directory inside the container, allowing you to access files from your local machine.

<a name="hardware-requirements"></a>

## Hardware Requirements
## ⚙️ Hardware Requirements

To ensure optimal performance and compatibility with the libraries used in this project, the following hardware specifications are recommended:

Expand All @@ -86,7 +128,7 @@ To ensure optimal performance and compatibility with the libraries used in this

<a name="usage"></a>

## Usage
## 📋 Usage

The `datadreamer/pipelines/generate_dataset_from_scratch.py` (`datadreamer` command) script is a powerful tool for generating and annotating images with specific objects. It uses advanced models to both create images and accurately annotate them with bounding boxes for designated objects.

Expand All @@ -98,36 +140,42 @@ datadreamer --save_dir <directory> --class_names <objects> --prompts_number <num

<a name="main-parameters"></a>

### Main Parameters
### 🎯 Main Parameters

- `--save_dir` (required): Path to the directory for saving generated images and annotations.
- `--class_names` (required): Space-separated list of object names for image generation and annotation. Example: person moon robot.
- `--prompts_number` (optional): Number of prompts to generate for each object. Defaults to 10.
- `--class_names` (required): Space-separated list of object names for image generation and annotation. Example: `person moon robot`.
- `--prompts_number` (optional): Number of prompts to generate for each object. Defaults to `10`.
- `--annotate_only` (optional): Only annotate the images without generating new ones, prompt and image generator will be skipped. Defaults to `False`.

<a name="additional-parameters"></a>

### Additional Parameters
### 🔧 Additional Parameters

- `--task`: Choose between `detection` and `classification`. Default is `detection`.
- `--task`: Choose between detection and classification. Default is `detection`.
- `--num_objects_range`: Range of objects in a prompt. Default is 1 to 3.
- `--prompt_generator`: Choose between `simple`, `lm` (language model) and `tiny` (tiny LM). Default is `simple`.
- `--image_generator`: Choose image generator, e.g., `sdxl`, `sdxl-turbo` or `sdxl-lightning`. Default is `sdxl-turbo`.
- `--image_annotator`: Specify the image annotator, like `owlv2`. Default is `owlv2`.
- `--conf_threshold`: Confidence threshold for object detection. Default is 0.15.
- `--use_tta`: Toggle test time augmentation for object detection. Default is True.
- `--enhance_class_names`: Enhance class names with synonyms. Default is False.
- `--use_image_tester`: Use image tester for image generation. Default is False.
- `--image_tester_patience`: Patience level for image tester. Default is 1.
- `--image_annotator`: Specify the image annotator, like `owlv2` for object detection or `clip` for image classification. Default is `owlv2`.
- `--conf_threshold`: Confidence threshold for annotation. Default is `0.15`.
- `--annotation_iou_threshold`: Intersection over Union (IoU) threshold for annotation. Default is `0.2`.
- `--prompt_prefix`: Prefix to add to every image generation prompt. Default is `""`.
- `--prompt_suffix`: Suffix to add to every image generation prompt, e.g., for adding details like resolution. Default is `", hd, 8k, highly detailed"`.
- `--negative_prompt`: Negative prompts to guide the generation away from certain features. Default is `"cartoon, blue skin, painting, scrispture, golden, illustration, worst quality, low quality, normal quality:2, unrealistic dream, low resolution, static, sd character, low quality, low resolution, greyscale, monochrome, nose, cropped, lowres, jpeg artifacts, deformed iris, deformed pupils, bad eyes, semi-realistic worst quality, bad lips, deformed mouth, deformed face, deformed fingers, bad anatomy"`.
- `--use_tta`: Toggle test time augmentation for object detection. Default is `True`.
- `--synonym_generator`: Enhance class names with synonyms. Default is `none`. Other options are `llm`, `wordnet`.
- `--use_image_tester`: Use image tester for image generation. Default is `False`.
- `--image_tester_patience`: Patience level for image tester. Default is `1`.
- `--lm_quantization`: Quantization to use for Mistral language model. Choose between `none` and `4bit`. Default is `none`.
- `--annotator_size`: Size of the annotator model to use. Choose between `base` and `large`. Default is `base`.
- `--batch_size_prompt`: Batch size for prompt generation. Default is 64.
- `--batch_size_annotation`: Batch size for annotation. Default is 8.
- `--batch_size_image`: Batch size for image generation. Default is 1.
- `--device`: Choose between `cuda` and `cpu`. Default is cuda.
- `--seed`: Set a random seed for image and prompt generation. Default is 42.
- `--batch_size_annotation`: Batch size for annotation. Default is `8`.
- `--batch_size_image`: Batch size for image generation. Default is `1`.
- `--device`: Choose between `cuda` and `cpu`. Default is `cuda`.
- `--seed`: Set a random seed for image and prompt generation. Default is `42`.

<a name="available-models"></a>

### Available models
### 🤖 Available Models

| Model Category | Model Names | Description/Notes |
| ----------------- | ------------------------------------------------------------------------------------- | --------------------------------------- |
Expand All @@ -138,10 +186,11 @@ datadreamer --save_dir <directory> --class_names <objects> --prompts_number <num
| | [SDXL-Turbo](https://huggingface.co/stabilityai/sdxl-turbo) | Fast and less accurate (512x512 images) |
| | [SDXL-Lightning](https://huggingface.co/ByteDance/SDXL-Lightning) | Fast and accurate (1024x1024 images) |
| Image Annotation | [OWLv2](https://huggingface.co/google/owlv2-base-patch16-ensemble) | Open-Vocabulary object detector |
| | [CLIP](https://huggingface.co/openai/clip-vit-base-patch32) | Zero-shot-image-classification |

<a name="example"></a>

### Example
### 💡 Example

```bash
datadreamer --save_dir path/to/save_directory --class_names person moon robot --prompts_number 20 --prompt_generator simple --num_objects_range 1 3 --image_generator sdxl-turbo
Expand All @@ -151,7 +200,7 @@ This command generates images for the specified objects, saving them and their a

<a name="output"></a>

### Output
### 📦 Output

The dataset comprises two primary components: images and their corresponding annotations, stored as JSON files.

Expand All @@ -169,7 +218,7 @@ save_dir/

<a name="annotations-format"></a>

### Annotations Format
### 📝 Annotations Format

1. Detection Annotations (detection_annotations.json):

Expand Down Expand Up @@ -202,35 +251,29 @@ save_dir/
}
```

<a name="note"></a>

### Note

Please make sure that all dependencies are correctly installed and that the datadreamer package is properly set up in your Python environment before running the script.

<a name="limitations"></a>

## Limitations
## ⚠️ Limitations

While the datadreamer library leverages advanced Generative models to synthesize datasets and Foundation models for annotation, there are inherent limitations to consider:

- `Incomplete Object Representation`: Occasionally, the generative models might not include all desired objects in the synthetic images. This could result from the complexity of the scene or limitations within the model's learned patterns.

- `Annotation Accuracy`: The annotations created by foundation computer vision models may not always be precise. These models strive for accuracy, but like all automated systems, they are not infallible and can sometimes produce erroneous or ambiguous labels.
- `Annotation Accuracy`: The annotations created by foundation computer vision models may not always be precise. These models strive for accuracy, but like all automated systems, they are not infallible and can sometimes produce erroneous or ambiguous labels. However, we have implemented several strategies to mitigate these issues, such as Test Time Augmentation (TTA), usage of synonyms for class names and careful selection of the confidence/IOU thresholds.

Despite these limitations, the datasets created by datadreamer provide a valuable foundation for developing and training models, especially for edge computing scenarios where data availability is often a challenge. The synthetic and annotated data should be seen as a stepping stone, granting a significant head start in the model development process.

<a name="license"></a>

## License
## 📄 License

This project is licensed under the [Apache License, Version 2.0](https://opensource.org/license/apache-2-0/) - see the [LICENSE](LICENSE) file for details.

The above license does not cover the models. Please see the license of each model in the table above.

<a name="acknowledgements"></a>

## Acknowledgements
## 🙏 Acknowledgements

This library was made possible by the use of several open-source projects, including Transformers, Diffusers, and others listed in the requirements.txt.

Expand Down
1 change: 1 addition & 0 deletions datadreamer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
5 changes: 4 additions & 1 deletion datadreamer/dataset_annotation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

from .clip_annotator import CLIPAnnotator
from .image_annotator import BaseAnnotator, TaskList
from .owlv2_annotator import OWLv2Annotator

__all__ = ["BaseAnnotator", "TaskList", "OWLv2Annotator"]
__all__ = ["BaseAnnotator", "TaskList", "OWLv2Annotator", "CLIPAnnotator"]
Loading
Loading