# train_utils

Python API: `luxonis_train.core.utils.train_utils`

The construction of the Lightning trainer from the config.

## Functions

### create_trainer

```python
def create_trainer(cfg: TrainerConfig, **kwargs: Any) -> pl.Trainer:
```

Create a Lightning trainer from the `trainer` config section.

The function passes these fields of `cfg` to the trainer:

 * `accelerator`, `devices`, `strategy`, `profiler`, `deterministic`, `gradient_clip_val`, `gradient_clip_algorithm`, and
   `overfit_batches` under the same names;
 * `epochs` as `max_epochs`;
 * `validation_interval` as `check_val_every_n_epoch`;
 * `n_sanity_val_steps` as `num_sanity_val_steps`.

The other fields, such as `precision`, do not reach the trainer through this function. The main trainer of
[LuxonisModel](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/core/core.md)
gets `precision` through `kwargs`.

Parameters

 * `cfg` (`TrainerConfig`): The `trainer` section of the config.
 * `**kwargs` (`Any`): More keyword arguments for the trainer, such as `logger`, `callbacks`, or `precision`. A key that the
   function already sets from `cfg` raises `TypeError`.

Returns

 * `pl.Trainer`: The trainer.
