Skip to content

Commit

Permalink
Nested Labels and Augmentation (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlov721 authored Jan 5, 2025
1 parent e52e62e commit 2a64197
Show file tree
Hide file tree
Showing 82 changed files with 5,315 additions and 4,443 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_ENDPOINT_URL: ${{ secrets.AWS_S3_ENDPOINT_URL }}
ROBOFLOW_API_KEY: ${{ secrets.ROBOFLOW_API_KEY }}
LUXONISML_BUCKET: luxonis-test-bucket
run:
pytest --cov --junitxml=junit.xml -o junit_family=legacy
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ data/*
.vscode
tests/data
*.zip
.idea/*
apidocs/
38 changes: 35 additions & 3 deletions luxonis_ml/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from importlib.metadata import version

import rich
import rich.box
import typer
from rich.markup import escape
from rich.table import Table

from luxonis_ml.utils import setup_logging

Expand All @@ -9,7 +13,7 @@
add_completion=True,
pretty_exceptions_show_locals=False,
)
setup_logging(use_rich=True)
setup_logging(use_rich=True, rich_print=True)

try:
from luxonis_ml.data.__main__ import app as data_app
Expand All @@ -35,7 +39,7 @@

def version_callback(value: bool):
if value:
print(f"LuxonisML: {version(__package__)}")
typer.echo(f"LuxonisML: {version('luxonis_ml')}")
raise typer.Exit()


Expand All @@ -49,9 +53,37 @@ def main(
help="Show version and exit.",
),
):
# Do other global stuff, handle other global options here
return


@app.command()
def checkhealth():
"""Check the health of the Luxonis ML library."""
table = Table(
title="Health Check",
box=rich.box.ROUNDED,
)
table.add_column("Module", header_style="magenta i")
table.add_column("Status", header_style="magenta i")
table.add_column("Error", header_style="magenta i", max_width=50)
for submodule in ["data", "utils", "nn_archive"]:
error_message = ""
try:
__import__(f"luxonis_ml.{submodule}")
status = "✅"
style = "green"
except ImportError as e:
status = "❌"
style = "red"
error_message = escape(str(e.args[0]))
if len(e.args) > 1:
error_message += f" [bold]{escape(e.args[1])}[/bold]"

table.add_row(submodule, status, error_message, style=style)

console = rich.console.Console()
console.print(table)


if __name__ == "__main__":
app()
25 changes: 12 additions & 13 deletions luxonis_ml/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@ def generator():
w, h = bbox["dimension"]

# get the class name of the bounding box
class_ = bbox["labelName"]
class_name = bbox["labelName"]
yield {
"file": image_path,
"annotation": {
"type": "boundingbox",
"class": class_,

# normalized bounding box
"x": x / W,
"y": y / H,
"w": w / W,
"h": h / H,
"class": class_name,

"boundingbox": {
# normalized bounding box
"x": x / W,
"y": y / H,
"w": w / W,
"h": h / H,
}
},
}
```
Expand Down Expand Up @@ -557,7 +558,6 @@ The following example demonstrates a simple augmentation pipeline:
'mask_pad_val': 0,
'fit_output': False,
'interpolation': 1,
'always_apply': False,
}
},
{
Expand All @@ -577,7 +577,6 @@ The following example demonstrates a simple augmentation pipeline:
'fit_output': False,
'keep_ratio': False,
'rotate_method': 'largest_box',
'always_apply': False,
}
},
]
Expand All @@ -593,13 +592,13 @@ For this example, we will assume the augmentation example above is stored in a J

```python

from luxonis_ml.data import LuxonisDataset, LuxonisLoader, Augmentations
from luxonis_ml.data import LuxonisDataset, LuxonisLoader, AlbumentationsEngine
import json

with open("augmentations.json") as f:
augmentations = json.load(f)

aug = Augmentations(image_size=[256, 320], augmentations=augmentations)
aug = AlbumentationsEngine(image_size=[256, 320], augmentations=augmentations)
dataset = LuxonisDataset("parking_lot")
loader = LuxonisLoader(dataset, view="train", augmentations=aug)

Expand Down
27 changes: 6 additions & 21 deletions luxonis_ml/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from luxonis_ml.guard_extras import guard_missing_extra

with guard_missing_extra("data"):
from .augmentations import Augmentations
from .augmentations import AlbumentationsEngine
from .datasets import (
DATASETS_REGISTRY,
BaseDataset,
Expand All @@ -12,31 +12,19 @@
LuxonisDataset,
LuxonisSource,
)
from .loaders import (
LOADERS_REGISTRY,
BaseLoader,
Labels,
LuxonisLoader,
LuxonisLoaderOutput,
)
from .loaders import LOADERS_REGISTRY, BaseLoader, LuxonisLoader
from .parsers import LuxonisParser
from .utils.enums import (
BucketStorage,
BucketType,
ImageType,
LabelType,
MediaType,
)
from .utils.enums import BucketStorage, BucketType, ImageType, MediaType


def load_dataset_plugins() -> None:
def load_dataset_plugins() -> None: # pragma: no cover
"""Registers any external dataset BaseDataset class plugins."""
for entry_point in pkg_resources.iter_entry_points("dataset_plugins"):
plugin_class = entry_point.load()
DATASETS_REGISTRY.register_module(module=plugin_class)


def load_loader_plugins() -> None:
def load_loader_plugins() -> None: # pragma: no cover
"""Registers any external dataset BaseLoader class plugins."""
for entry_point in pkg_resources.iter_entry_points("loader_plugins"):
plugin_class = entry_point.load()
Expand All @@ -47,7 +35,7 @@ def load_loader_plugins() -> None:
load_loader_plugins()

__all__ = [
"Augmentations",
"AlbumentationsEngine",
"BaseDataset",
"BaseLoader",
"BucketStorage",
Expand All @@ -56,12 +44,9 @@ def load_loader_plugins() -> None:
"DATASETS_REGISTRY",
"LOADERS_REGISTRY",
"ImageType",
"LabelType",
"Labels",
"LuxonisComponent",
"LuxonisDataset",
"LuxonisLoader",
"LuxonisLoaderOutput",
"LuxonisParser",
"LuxonisSource",
"MediaType",
Expand Down
Loading

0 comments on commit 2a64197

Please sign in to comment.