Constructor for the sg_trained_model S3 class, representing a trained
segmentation model with associated metadata.
Arguments
- model_path
Character. Path to the trained model weights.
- backend
Character. Segmentation backend:
"cellpose"or"stardist".- base_model
Character. Name of the base model that was fine-tuned.
- training_metrics
Named list of training metrics (e.g., loss curve, number of epochs).
- model_card
Named list of model card metadata (description, author, intended use, etc.). The versioned card written by
sg_package_model()readspurpose,data_domain,channels,target_pixel_size_um,input_value_semantics,normalization,limitations(character),evaluation(named list of metrics) andlicensefrom here.- runtime
Optional runtime description (list) recorded at training time; never a copy of a Python environment.
- dataset_manifest
Optional
sg_dataset_manifestthe model was trained on.- license
Optional list with
id(e.g. an SPDX identifier),name,sourceandtext.- representation
Weight representation:
"pb","savedmodel","bioimageio","pytorch","keras","directory","file"or"unknown".
Examples
# a dedicated directory with a stand-in weight file
weights <- file.path(tempfile("model"), "cellpose_weights")
dir.create(dirname(weights))
writeBin(as.raw(1:16), weights)
mdl <- new_sg_trained_model(
model_path = weights,
backend = "cellpose",
base_model = "cyto3",
training_metrics = list(n_epochs = 100L, final_loss = 0.05)
)
print(mdl)
#> <sg_trained_model>
#> Backend: cellpose
#> Base model: cyto3
#> Model path: /tmp/RtmpZNYdOa/model1f6c45f26b15/cellpose_weights
#> Epochs: 100
#> Final loss: 0.05
#> Created: 2026-11-22 06:25:01