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

Nested Labels and Augmentation #211

Open
wants to merge 146 commits into
base: main
Choose a base branch
from
Open

Nested Labels and Augmentation #211

wants to merge 146 commits into from

Conversation

kozlov721
Copy link
Collaborator

@kozlov721 kozlov721 commented Dec 3, 2024

Labels and Augmentations refactor

Nested Labels

  • Added native support for arbitrarily nested labels
  • Added new "metadata" field that can hold additional information about the label
    • Can be int, float, or string
  • "task" moved up from the "annotation" section
    • An image without labels still belongs to some task
  • Groundwork for future support of multiple images per annotation
  • Added support for instance segmentation tasks
    • New "instance_segmentation" task type

Example

yield {
    "file": "img.png",
    "task": "vehicles",
    "annotation": {
        "class": "car",
        "boundingbox": {
            "x": x, "y": y, "w": w, "h": h
        },
        "keypoints": {
            "keypoints": [...]
        },
        "instance_segmentation": {
            "mask": ...
        },
        "array": {"path": ...},
        "metadata": {
            "id": 12,
        },
        "sub_detections": {
            "license_plate": {
                "boundingbox": {...},
                "metadata": {
                    "text": "123ABC"
                },
            }
        }
    }
}

The output of the loader for the above annotations would be:

{
    "vehicles/boundingbox": ...,
    "vehicles/keypoints": ...,
    "vehicles/instance_segmentation": ...,
    "vehicles/classification": ...,
    "vehicles/array": ...,
    "vehicles/metadata/id": ...,
    "vehicles/license_plate/boundingbox": ...,
    "vehicles/license_plate/metadata/text": ...,
}

Augmentations

  • Upgraded albumentations from 1.3.x to 1.4.x
  • Added support for multiple batched augmentations
    • e.g. MixUp together with Mosaic4
  • Improved MixUp augmentation
    • Uses letterbox resizing by default
      • Can be configured by keep_aspect_ration parameter
    • Improved augmenting semantic segmentations
      • Masks are blended together, in case of a conflict, the mask associated with higher $\alpha$ takes precedence
  • Native support for labels with multiple annotations of the same type
    • Instead of it being a hack on the LuxonisLoader part
  • Cleaned up and removed unused code
  • Overall performance increase for all types of augmentations (see the table below)
  • Augmentations are now initialized by BaseLoader instead of by the user
    • This allows for augmenting all annotations in one go using albumentation's additional_targets logic
    • Simplified usage for users
      -Augmentations renamed to AlbumentationsEngine and inherit from AugmentationEngine
      • Groundwork for future support for more augmentation engines
      • Users can implement their own engine which registers into AUGMENTATION_ENGINES registry

Example
old.py

from luxonis_ml.data import LuxonisDataset, LuxonisLoader, Augmentations


dataset = LuxonisDataset(...)
augmentations = Augmentations((height, width), config, ...)
loader = LuxonisLoader(dataset, augmentations, ...)

new.py

from luxonis_ml.data import LuxonisDataset, LuxonisLoader

dataset = LuxonisDataset(...)
loader = LuxonisLoader(
    dataset, 
    height=...,
    width=...,
    # possible future support for other engines, e.g. Nvidia's DALI
    augmentation_engine="albumentations",
    augmentation_config=...,
    ...,
)

Benchmark

Benchmarking was done on Microsoft COCO 2017 Dataset. The size of the dataset is 92,325 images.
The new augmentations are faster in all categories.

Action Old New
Dataset Creation 118s 112s
Loader Init 184s 138s
Iterating No Augmentation 91s 89s
Iterating Standard Augmentations 620s 582s
Iterating MixUp Augmentation 401s 307s
Iterating Mosaic4 Augmentation 590s 505s

Miscellaneous

  • Added new directory tools to the repository that will contain various scripts for easier development
    • Currently contains benchmark.py and migrate.py
  • LuxonisDataset checks the LDF version for compatibility
  • Added new luxonis_ml checkhealth command that prints a table with the state of individual sub-packages including possible import errors
  • Custom types moved to luxonis_ml.typing
  • Improved visualization functions for luxonis_ml data inspect
    • Nested labels rendered on top of each other
    • Occluded keypoints marked with a cross
    • Nested bounding boxes rendered using dashed lines
    • Added --keep_aspect_ratio (or -k) flag to use letterbox resizing with augmentations
    • Added --blend-all (or -b) flag to draw all labels on top of the same image (disregarding different tasks)
      image

Migration

It is possible to migrate datasets created with previous version of luxonis-ml using the tools/migrate.py script:

python tools/migrate.py name_of_dataset team_id

If no arguments are provided, the script will migrate all outdated datasets under the active LUXONISML_BASE_PATH with the default team_id.

@kozlov721 kozlov721 requested a review from a team as a code owner December 3, 2024 23:01
@kozlov721 kozlov721 removed the request for review from a team December 3, 2024 23:01
@github-actions github-actions bot added the DevOps Changes related to DevOps label Dec 13, 2024
Copy link
Collaborator

@klemen1999 klemen1999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!
Let's fix the tests and then we can merge IMO

tools/migrate.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI Changes affecting the CLI data Changes affecting luxonis_ml.data subpackage DevOps Changes related to DevOps documentation Improvements or additions to documentation enhancement New feature or request NN Archive Changes affecting luxonis_ml.nn_archive subpackage tests Adding or changing tests tracker Changes affecting luxonis_ml.tracker subpackage utils Changes affecting luxonis_ml.utils subpackage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants