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

Documentation refactoring #120

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
> \[!NOTE\]\
> This is the latest version of tools CLI. If you are looking for the tools web application, please refer to the [web-app](https://github.com/luxonis/tools/tree/web-app) branch.

This application is used for exporting Yolo V5, V6, V7, V8 (OBB, instance segmentation, pose estimation, cls) and Gold YOLO object detection models to .ONNX.
This is a command-line tool that simplifies the conversion process of YOLO models. It supports the conversion of YOLOs ranging from V5 through V11 and Gold Yolo including oriented bounding boxes object detection (OBB), pose estimation, and instance segmentation variants of YOLOv8 and YOLO11 to ONNX format.

> \[!WARNING\]\
> Please note that for the moment, we support conversion of YOLOv9 weights only from [Ultralytics](https://docs.ultralytics.com/models/yolov9/#performance-on-ms-coco-dataset).

## Running

You can either export a model stored on cloud (e.g. S3) or locally. To export a local model, please put it inside a `shared-component` folder.
You can either export a model stored on the cloud (e.g. S3) or locally. You can choose to install the toolkit through pip or using Docker. In the sections below, we'll describe both options.

The output files are going to be in `shared-component/output` folder.
### Using Python package

```bash
# Install the package
pip install tools@git+https://github.com/luxonis/tools.git@main
# Running the package
tools yolov6nr4.pt --imgsz "416"
```

### Using Docker or Docker Compose

### Prerequisites
This option requires you to have Docker installed on your device. Additionally, to export a local model, please put it inside a `shared-component/models/` folder in the root folder of the project.

#### Prerequisites

```bash
# Cloning the tools repository and all submodules
Expand All @@ -20,7 +34,7 @@ git clone --recursive https://github.com/luxonis/tools.git
cd tools
```

### Using Docker
#### Using Docker

```bash
# Building Docker image
Expand All @@ -29,7 +43,7 @@ docker build -t tools_cli .
docker run -v "${PWD}/shared_with_container:/app/shared_with_container" tools_cli shared_with_container/models/yolov8n-seg.pt --imgsz "416"
```

### Using Docker compose
#### Using Docker compose

```bash
# Building Docker image
Expand All @@ -38,14 +52,7 @@ docker compose build
docker compose run tools_cli shared_with_container/models/yolov6nr4.pt
```

### Using Python package

```bash
# Building the package
pip install .
# Running the package
tools shared_with_container/models/yolov6nr4.pt --imgsz "416"
```
The output files are going to be in `shared-component/output` folder.

### Arguments

Expand All @@ -60,7 +67,7 @@ tools shared_with_container/models/yolov6nr4.pt --imgsz "416"

## Credits

This application uses source code of the following repositories: [YOLOv5](https://github.com/ultralytics/yolov5), [YOLOv6](https://github.com/meituan/YOLOv6), [GoldYOLO](https://github.com/huawei-noah/Efficient-Computing) [YOLOv7](https://github.com/WongKinYiu/yolov7), and [Ultralytics YOLOv8](https://github.com/ultralytics/ultralytics) (see each of them for more information).
This application uses source code of the following repositories: [YOLOv5](https://github.com/ultralytics/yolov5), [YOLOv6](https://github.com/meituan/YOLOv6), [GoldYOLO](https://github.com/huawei-noah/Efficient-Computing) [YOLOv7](https://github.com/WongKinYiu/yolov7), and [Ultralytics](https://github.com/ultralytics/ultralytics) (see each of them for more information).

## License

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ torchvision>=0.10.1
Pillow>=7.1.2
PyYAML>=5.3.1
gcsfs
luxonis-ml[data,nn_archive]>=0.4.0
luxonis-ml[data,nn_archive]>=0.4.1
# luxonis-ml[data,nn_archive] @ git+https://github.com/luxonis/luxonis-ml@dev
onnx>=1.10.1
onnxruntime
Expand Down
43 changes: 34 additions & 9 deletions tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional

import typer
from typing_extensions import Annotated

from tools.utils import (
GOLD_YOLO_CONVERSION,
Expand Down Expand Up @@ -46,14 +47,38 @@

@app.command()
def convert(
model: str,
imgsz: str = "416 416",
version: Optional[str] = None,
use_rvc2: bool = True,
class_names: Optional[str] = None,
output_remote_url: Optional[str] = None,
config_path: Optional[str] = None,
put_file_plugin: Optional[str] = None,
model: Annotated[str, typer.Argument(help="Path to the model file.")],
imgsz: Annotated[
str, typer.Option(help="Input image size [width, height].")
] = "416 416",
version: Annotated[
Optional[str],
typer.Option(
help='YOLO version (e.g. `"yolov8"`). If `None`, the toolkit will run an automatic version detector.'
),
] = None,
use_rvc2: Annotated[
bool, typer.Option(help="Whether the target platform is RVC2 or RVC3.")
] = True,
class_names: Annotated[
Optional[str],
typer.Option(
help='A list of class names the model is capable of recognizing (e.g. `"person, bicycle, car"`).'
),
] = None,
output_remote_url: Annotated[
Optional[str], typer.Option(help="An URL to upload the output to.")
] = None,
config_path: Annotated[
Optional[str],
typer.Option(help="An optional path to a conversion config file."),
] = None,
put_file_plugin: Annotated[
Optional[str],
typer.Option(
help="The name of a registered function under the PUT_FILE_REGISTRY."
),
] = None,
):
logger = logging.getLogger(__name__)
logger.info("Converting model...")
Expand Down Expand Up @@ -146,7 +171,7 @@ def convert(
try:
logger.info("Creating NN archive...")
exporter.export_nn_archive(config.class_names)
logger.info("NN archive created.")
logger.info(f"NN archive created in {exporter.output_folder}.")
except Exception as e:
logger.error(f"Error creating NN archive: {e}")
raise typer.Exit(code=1) from e
Expand Down
2 changes: 1 addition & 1 deletion tools/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Config(LuxonisConfig):
default=[416, 416],
min_length=2,
max_length=2,
min_ledescription="Image size [width, height].",
min_ledescription="Input image size [width, height].",
)
class_names: Optional[List[str]] = Field(None, description="List of class names.")
use_rvc2: Literal[False, True] = Field(True, description="Whether to use RVC2.")
Expand Down
Loading