spacr.model_check

Check whether a model is compatible with spaCR and the chosen classes.

The check runs before training and answers three questions, in the order they can fail:

  1. Can it be loaded at all? A custom path may hold a checkpoint saved by a different framework, a state dict with no architecture, or a corrupt file.

  2. Does it take the input this dataset produces – the right number of image channels, at the chosen size?

  3. Does it produce the right number of classes?

The third fails silently: a two-class head on a three-class problem trains without error and is wrong about every object of the third class.

A custom model that loads supersedes model_type. No separate flag selects between them.

Classes

ModelReport

Result of a model compatibility check.

Functions

check_model(→ ModelReport)

Whether the chosen model can train on the chosen data and classes.

expected_channels(→ Optional[int])

How many image channels this dataset will hand the model.

expected_classes(→ Optional[int])

How many classes the training set will have.

resolve_model_source(→ Tuple[str, str])

(kind, name) for the model that will actually be used.

Module Contents

class spacr.model_check.ModelReport[source]

Result of a model compatibility check.

Parameters:
  • ok – whether the compatibility check found no blocking problem.

  • source – display identifier for the checked model: a built-in name, custom-file basename, or "no model".

  • problems – blocking diagnostic messages used by the unsuccessful summary.

  • notes – non-blocking compatibility facts retained separately and appended to the summary when ok is true.

  • channels – dataset input-channel count requested by the settings, or None when it cannot be determined.

  • classes – requested class count derived from the class definitions, or None when it cannot be determined.

summary() → str[source]

Return a one-line verdict followed by its notes or blocking problems.

spacr.model_check.check_model(settings: Mapping[str, Any]) → ModelReport[source]

Whether the chosen model can train on the chosen data and classes.

Parameters:

settings – classification settings to validate against the model.

Never raises; problems are reported in the returned ModelReport.

spacr.model_check.expected_channels(settings: Mapping[str, Any]) → int | None[source]

How many image channels this dataset will hand the model.

Parameters:

settings – classification settings containing channel declarations.

spacr.model_check.expected_classes(settings: Mapping[str, Any]) → int | None[source]

How many classes the training set will have.

Parameters:

settings – classification settings containing class definitions.

spacr.model_check.resolve_model_source(settings: Mapping[str, Any]) → Tuple[str, str][source]

(kind, name) for the model that will actually be used.

Parameters:

settings – classification settings containing model choices.

kind is 'custom' or 'builtin'. A custom path that exists takes precedence; otherwise model_type is used.