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

added model export to readme and cli #43

Merged
merged 2 commits into from
Dec 9, 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
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ pip install trolo
The D-FINE model redefines regression tasks in DETR-based detectors using Fine-grained Distribution Refinement (FDR).
[Official Paper](https://arxiv.org/abs/2410.13842) | [Official Repo](https://github.com/Peterande/D-FINE)
![D-FINE Model Stats](https://raw.githubusercontent.com/Peterande/storage/master/figs/stats_padded.png)
</details>

( All models will be automatically downloaded when you pass the name for any task)

| Model | Dataset | AP<sup>val</sup> | #Params | Latency | GFLOPs |
| :---: | :---: | :---: | :---: | :---: | :---: |
`dfine-n` | COCO | **42.8** | 4M | 2.12ms | 7
Expand All @@ -56,7 +58,7 @@ The D-FINE model redefines regression tasks in DETR-based detectors using Fine-g
`dfine-l` | COCO | **54.0** | 31M | 8.07ms | 91
`dfine-x` | COCO | **55.8** | 62M | 12.89ms | 202

</details>


<details>
<summary><b>RT-DETR v3 (Coming Soon)</b></summary>
Expand Down Expand Up @@ -109,6 +111,23 @@ poltted_preds = predictor.visualize(show=True, save=True) # or get visualized ou
Visit Inference Docs for more details



### Model export
Example export command:
```bash
trolo export --model dfine-n --export_format onnx --input_size 640
```
Python API:

```
python from trolo.inference import ModelExporter model_path = "/path/to/model"
input_size = 640 # Inference resolution
export_format = "onnx"
exporter = ModelExporter(model=model_path) exporter.export(input_size=input_size, export_format=export_format)
```
Visit Export Docs for more details


### Training
<b>Example training command:</b>
```bash
Expand Down
13 changes: 13 additions & 0 deletions trolo/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from trolo.trainers.detection import DetectionTrainer
from trolo.inference.detection import DetectionPredictor
from trolo.export.exporter import ModelExporter
from trolo.utils.smart_defaults import (
infer_device,
infer_pretrained_model,
Expand Down Expand Up @@ -82,6 +83,18 @@ def eval(model, device, batch_size):
eval_detection(model, device=device, **overrides)


@cli.command()
@click.option("--model", "-m", type=str, default=DEFAULT_MODEL, help="Model name or path")
@click.option("--input_size", "-i", type=int, default=640, help="Inference input size")
@click.option("--export_format", "-e", type=str, default=None, help="Export format")
def export(model, input_size, export_format):
"""Run inference on images using a trained model"""

# Initialize predictor with smart defaults
exporter = ModelExporter(model=infer_pretrained_model(model))
exporter.export(input_size=input_size, export_format=export_format)


def main():
cli()

Expand Down
Loading