Concepts
Overview
Configuration
Configuration Components
- Model: Defines the architecture of your model, including nodes, losses, visualizers and metrics.
- Loader: Configures data loading by selecting the appropriate dataset. For more details on how to create a dataset, refer to the Data Preparation section.
- Trainer: Specifies training parameters, including batch size, epochs, preprocessing (normalization, augmentations), optimizer, scheduler, callbacks, and more. For more details, refer to the Training section.
- Tracker: Monitors and logs training metrics for analysis. For more details, refer to the Training section.
- Exporter: Defines export settings for your trained model to ensure compatibility and performance on deployment platforms. For more details, refer to the Exporting section.
- Tuner: Tunes hyperparameters to optimize model performance. For more details, refer to the Training section.
Example Configuration File
Yaml
1model:
2 name: model_name
3
4 # Use a predefined detection model instead of manually defining the architecture
5 predefined_model:
6 name: DetectionModel
7 variant: light
8 params:
9 loss_params:
10 iou_type: "siou"
11 n_warmup_epochs: 0
12
13# Dataset configuration: Download and parse the COCO dataset from RoboFlow
14loader:
15 params:
16 dataset_name: coco_test
17 dataset_dir: "roboflow://team-roboflow/coco-128/2/coco"
18
19trainer:
20 batch_size: 8
21 epochs: 200
22 n_workers: 8
23 validation_interval: 10
24
25 preprocessing:
26 train_image_size: [384, 384]
27
28 # Image normalization using ImageNet standards
29 normalize:
30 active: true
31
32 # Image augmentations using Albumentations library
33 augmentations:
34 - name: Defocus
35 - name: Sharpen
36 - name: Flip
37
38 callbacks:
39 - name: ExportOnTrainEnd
40 - name: ArchiveOnTrainEnd
41 - name: TestOnTrainEnd
42
43 optimizer:
44 name: SGD
45 params:
46 lr: 0.02
47
48 scheduler:
49 name: ConstantLRPredefined Models
Customization
Custom Components
Example: Custom Callback
Python
1import lightning.pytorch as pl
2
3from luxonis_train import LuxonisLightningModule
4from luxonis_train.utils.registry import CALLBACKS
5
6
7@CALLBACKS.register()
8class CustomCallback(pl.Callback):
9 def __init__(self, message: str, **kwargs):
10 super().__init__(**kwargs)
11 self.message = message
12
13 # Will be called at the end of each training epoch.
14 # Consult the PyTorch Lightning documentation for more callback methods.
15 def on_train_epoch_end(
16 self,
17 trainer: pl.Trainer,
18 pl_module: LuxonisLightningModule,
19 ) -> None:
20 print(self.message)Example: Custom Loss Function
Python
1import lightning.pytorch as pl
2
3from luxonis_train import LuxonisLightningModule
4from luxonis_train.utils.registry import CALLBACKS
5
6
7@CALLBACKS.register()
8class CustomCallback(pl.Callback):
9 def __init__(self, message: str, **kwargs):
10 super().__init__(**kwargs)
11 self.message = message
12
13 # Will be called at the end of each training epoch.
14 # Consult the PyTorch Lightning documentation for more callback methods.
15 def on_train_epoch_end(
16 self,
17 trainer: pl.Trainer,
18 pl_module: LuxonisLightningModule,
19 ) -> None:
20 print(self.message)Using Custom Components in Configuration
Yaml
1model:
2 nodes:
3 - name: SegmentationHead
4 losses:
5 - name: CustomLoss
6 params:
7 smoothing: 0.0001
8
9trainer:
10 callbacks:
11 - name: CustomCallback
12 params:
13 lr: "Hello from the custom callback!"Including Custom Components in Training
Using the CLI
Command Line
1luxonis_train --source custom_components.py train --config config.yamlUsing the Python API
Python
1# Import your custom components first
2from custom_components import *
3from luxonis_train import LuxonisModel
4
5model = LuxonisModel("config.yaml")
6model.train()