Package: luxonis-train
Luxonis Training FrameworkLuxonis training framework (luxonis-train) is intended for training deep learning models that can run fast on OAK products.The project is in an alpha state - please report any feedback.Table Of ContentsInstallationTrainingCustomizationsTuningExportingCredentialsContributingInstallationluxonis-trainis hosted on PyPi and can be installed withpipas:pipinstallluxonis-trainThis command will also create aluxonis_trainexecutable in yourPATH.
Seeluxonis_train --helpfor more information.UsageThe entire configuration is specified in ayamlfile. This includes the model
structure, used losses, metrics, optimizers etc. For specific instructions and example
configuration files, seeConfiguration.Data PreparationThis library requires data to be in the Luxonis Dataset Format.For instructions on how to create a dataset in the LDF, follow theexamplesin
theluxonis-mlrepository.TrainingOnce you've created yourconfig.yamlfile you can train the model using this command:luxonis_traintrain--configconfig.yamlIf you wish to manually override some config parameters you can do this by providing the key-value pairs. Example of this is:luxonis_traintrain--configconfig.yamltrainer.batch_size8trainer.epochs10where key and value are space separated and sub-keys are dot (.) separated. If the configuration field is a list, then key/sub-key should be a number (e.g.trainer.preprocessing.augmentations.0.name RotateCustom).TuningTo improve training performance you can useTunerfor hyperparameter optimization.
To use tuning, you have to specifytunersection in the config file.To start the tuning, runluxonis_traintune--configconfig.yamlYou can see an example tuning configurationhere.ExportingWe support export toONNX, andDepthAI .blob formatwhich is used for OAK cameras. By default, we export toONNXformat.To use the exporter, you have to specify theexportersection in the config file.Once you have the config file ready you can export the model usingluxonis_trainexport--configconfig.yamlYou can see an example export configurationhere.CustomizationsWe provide a registry interface through which you can create newnodes,losses,metrics,visualizers,callbacks,optimizers,
andschedulers.Registered components can be then referenced in the config file. Custom components need to inherit from their respective base classes:Node -BaseNodeLoss -BaseLossMetric -BaseMetricVisualizer -BaseVisualizerCallback -Callback from lightning.pytorch.callbacksOptimizer -Optimizer from torch.optimScheduler -LRScheduler from torch.optim.lr_schedulerHere is an example of how to create a custom components:fromtorch.optimimportOptimizerfromluxonis_train.utils.registryimportOPTIMIZERSfromluxonis_train.attached_modules.lossesimportBaseLoss@OPTIMIZERS.register_module()classCustomOptimizer(Optimizer):...# Subclasses of BaseNode, LuxonisLoss, LuxonisMetric# and BaseVisualizer are registered automatically.classCustomLoss(BaseLoss):# This class is automatically registered under `CustomLoss` name.def__init__(self,k_steps:int,**kwargs):super().__init__(**kwargs)...And then in the config you reference thisCustomOptimizerandCustomLossby their names:losses:-name:CustomLossparams:# additional parametersk_steps:12For more information on how to define custom components, consult the respective in-source documentation.CredentialsLocal use is supported by default. In addition, we also integrate some cloud services which can be primarily used for logging and storing. When these are used, you need to load environment variables to set up the correct credentials.You have these options how to set up the environment variables:Using standard environment variablesSpecifying the variables in a.envfile. If a variable is both in the environment and present in.envfile, the exported variable takes precedense.Specifying the variables in theENVIRONsection of the config file. Note that this is not a recommended way. Variables defined in config take precedense over environment and.envvariables.S3If you are working with LuxonisDataset that is hosted on S3, you need to specify these env variables:AWS_ACCESS_KEY_ID=**********AWS_SECRET_ACCESS_KEY=**********AWS_S3_ENDPOINT_URL=**********MLFlowIf you want to use MLFlow for logging and storing artifacts you also need to specify MLFlow-related env variables like this:MLFLOW_S3_BUCKET=**********MLFLOW_S3_ENDPOINT_URL=**********MLFLOW_TRACKING_URI=**********WanDBIf you are using WanDB for logging, you have to sign in first in your environment.POSTGRESSThere is an option for remote storage forTuning. We use POSTGRES and to connect to the database you need to specify the folowing env variables:POSTGRES_USER=**********POSTGRES_PASSWORD=**********POSTGRES_HOST=**********POSTGRES_PORT=**********POSTGRES_DB=**********ContributingIf you want to contribute to the development, install the dev version of the package:pipinstallluxonis-train[dev]Consult theContribution guidefor further instructions.