spacr.classification_pixels¶
Versioned crop decoding shared by classification and its checkpoints.
Functions¶
|
Read a checkpoint's decoder contract, preserving historical untagged models. |
|
Select decoding before training loaders are built for a resumed model. |
|
Find the decoding record through loaders, subsets and combined datasets. |
|
Decode a path or archive stream using the model's recorded policy. |
|
Record actual loader decoding and reject checkpoint or validation conflicts. |
|
Accept only implemented crop decoding policies; never guess a new one. |
Module Contents¶
- spacr.classification_pixels.checkpoint_policy(metadata, *, announce=False)[source]¶
Read a checkpoint’s decoder contract, preserving historical untagged models.
- Parameters:
metadata – artifact mapping returned by
load_model_artifact.announce – explain the legacy fallback when the contract is absent.
- Returns:
validated policy name. Missing metadata selects stored PIL RGB.
- spacr.classification_pixels.initialization_policy(path)[source]¶
Select decoding before training loaders are built for a resumed model.
- Parameters:
path – trusted checkpoint path, or None for a new training run.
- Returns:
saved policy, legacy fallback, or declared uint8 for new training.
- spacr.classification_pixels.loader_policy(loader)[source]¶
Find the decoding record through loaders, subsets and combined datasets.
Unknown external tensor datasets return None. Mixed recorded policies are refused because a single checkpoint cannot describe both transformations.
- Parameters:
loader – loader or dataset exposing
crop_loading_policy,datasetordatasets.- Returns:
a validated policy name, or None if no policy is recorded.
- Raises:
ValueError – a policy is unsupported or combined datasets disagree, including a mixture of recorded and unknown policies.
- spacr.classification_pixels.read_classification_image(source, policy=DECLARED_UINT8, *, fmt=None, legacy_orient=False)[source]¶
Decode a path or archive stream using the model’s recorded policy.
- Parameters:
source – image path or seekable binary stream, as accepted by PIL.
policy – declared uint8 decoding or historical stored PIL RGB.
fmt – source format; None resolves the path’s per-file crop marker. Archive callers must supply a format (1 when unmarked).
legacy_orient – retain the labelled loader’s historical EXIF handling.
- Returns:
independently owned PIL RGB image with its file handle closed.
- spacr.classification_pixels.training_preprocessing(train_loader, validation_loader, preprocessing=None, checkpoint=None)[source]¶
Record actual loader decoding and reject checkpoint or validation conflicts.
- Parameters:
train_loader – training loader or dataset whose decoding is inspected.
validation_loader – validation loader or dataset checked for agreement.
preprocessing – optional preprocessing mapping copied into the result; an explicit policy must agree with a recorded training policy.
checkpoint – optional loaded checkpoint metadata checked against the selected policy; an untagged checkpoint uses the historical policy.
- Returns:
a new preprocessing dictionary, including the policy when known. Unknown external datasets are not assigned a decoder automatically.
- Raises:
ValueError – a supplied policy is unsupported or the recorded training, validation, preprocessing or checkpoint policies conflict.
- spacr.classification_pixels.validate_policy(policy)[source]¶
Accept only implemented crop decoding policies; never guess a new one.
- Parameters:
policy –
declared_uint8_v1orstored_pil_v1.- Returns:
the unchanged, validated policy name.
- Raises:
ValueError – the supplied policy is not implemented.