Export - LightlyTrain documentation (original) (raw)

View this page

Toggle table of contents sidebar

The export command is used to prepare a model for fine-tuning or inference. It allows exporting the model from training checkpoints which contain additional information such as optimizer states that are not needed for fine-tuning or inference.

Tip

After training the model is automatically exported in the default format of the used library to out/my_experiment/exported_models/exported_last.pt.

Python

import lightly_train

if name == "main": lightly_train.train( out="out/my_experiment", data="my_data_dir", model="torchvision/resnet50", )

lightly_train.export(
    out="my_exported_model.pt",
    checkpoint="out/my_experiment/checkpoints/last.ckpt",
    part="model",
    format="torch_state_dict",
)

Command Line

lightly-train train out="out/my_experiment" data="my_data_dir" model="torchvision/resnet50" lightly-train export out="my_exported_model.pt" checkpoint="out/my_experiment/checkpoints/last.ckpt" part="model" format="torch_state_dict"

The above code example trains a model and exports the last training checkpoint as a torch state dictionary.

Out

The out argument specifies the output file where the exported model is saved.

Checkpoint

The checkpoint argument specifies the LightlyTrain checkpoint to use for exporting the model. This is the checkpoint saved to out/my_experiment/checkpoints/<some>.ckpt after training.

Format

The optional format argument specifies the format in which the model is exported. The following formats are supported.

Part

The optional part argument specifies which part of the model to export. The following parts are supported.