library("rplatypus")
export_weights(fit, "weights/my-run",
data = "our 2026 cohort", licence = "internal use only")Save a trained model’s weights
Description
Writes safetensors plus a .json sidecar recording what the weights are for: architecture, input shape, channels, classes, and whatever else you pass. Loading refuses a model they do not belong to, which is what the sidecar is for - weights trained on a different colormap with the same number of classes load cleanly and predict nonsense.
Usage
export_weights(object, path, model = NULL, ...)
Arguments
object
|
A platypus_fit().
|
path
|
Where to write, with or without the .safetensors extension.
|
model
|
Which model, by the name in the specification. Defaults to the first. |
…
|
Extra fields for the sidecar, for instance data = “BBBC038v1”, licence = “CC0 1.0”.
|
Details
Anything in … joins the sidecar. The data they were trained on and its licence belong there: weights whose provenance lives in somebody’s memory cannot be used by anybody else, including you in a year.
Value
The path written, invisibly, with the sidecar’s contents attached as the recorded attribute - so you can see what was put beside the weights without opening the file.
What the engine writes without being asked
Two things, since engine 0.8.0a75, and they are the ones a caller is in no position to know: trained_with, the engine version that produced the file, and measured_with - the engine that measured the figures beside the weights and the configuration it measured them with, resolved rather than as it was written.
Resolved is the whole point. metric_cldice()’s iterations is the skeleton’s peel count; it moves the number by about five points on one published set of weights, and before this it appeared in no file, because nobody had written it down - it was the metric’s own default. A sidecar recording only what a configuration stated would have recorded nothing about it.
What is in the block is task-specific, because the question is. The MODEL’s half asks how the figures were computed: a segmentation or classification fit records its metrics, an instance fit adds how objects were separated and decoded, and a detection fit records the three thresholds its table moves with and has no metric list at all.
And since engine 0.8.0a79 the block carries the DATA’s half beside it - how the data was read, which decides what the figures were measured on rather than how they were computed. window for every task, and channels_from and target_spacing for a SEMANTIC segmentation fit only - an instance fit records neither, because the two halves of a specification inherit differently: an instance model extends the segmentation model and so has splits, while instance data extends the base data class and so has only window. The reason they belong there is the reason splits does: they change a reported number while the weights and the data stay the same. Reading the same volumes at a different target_spacing scores a different number of real voxels at an identical model input shape, and a scan read on a lung window is not the picture the same scan is on a soft-tissue one.
And since engine 0.8.0a80 the same block answers a second question about the data: which cases were scored. split is recorded when a run partitions one folder instead of naming a second, and it is the companion to the paragraph above rather than more of it - that one says what the pictures looked like when they were measured, this one says which pictures there were. A reader who has the first and not the second can reproduce the windowing and still score a different set of images.
It is recorded resolved, which is where its value is. fractions alone describes a partition; fractions with group_by and seed and the files that were found determines it. So seed is there even when nobody wrote one - it defaults to 0 and arrives by resolution - and group_by is there because that is what makes a split by patient rather than by slice, which is the difference split_dataset() exists to let you keep.
split is not splits, and they now sit in the same block one letter apart. split is the data’s partition: which cases were held out. splits is the model’s tiling: a source image read at splits times input_shape and cut into pieces. One decides how many cases there are, the other which pictures a metric sees inside one case.
The data’s half records only what was set, and that asymmetry is the useful part. A missing split means this run named a second folder, so nothing was partitioned, and a missing target_spacing means this run named none, not resampled to nothing: the field defaults to NULL, and a record that wrote null could not be told apart from one written by an engine too old to answer. window is the exception and is always there, because it always has a value - “auto” is a windowing rather than an absence, and it means whatever window the file itself recorded, so two datasets read with “auto” are not necessarily read alike.
Passing either of those names in … is refused rather than ignored, because a caller’s copy of a fact only the engine knows is a copy that will drift.