spacr.model_check

Is this model compatible with spaCR, and with the classes chosen?

Clicking a model should say whether it will work before an hour of training finds out. 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 is the one that silently half-works: a two-class head on a three-class problem trains happily and is wrong about every object of the third class.

A custom model that loads supersedes model_type. There is no boolean saying which to believe, because a path that holds a working model is a complete answer on its own and a flag that disagreed with it would just be a second thing to get wrong.

Classes

ModelReport

What was found. ok first, because it is the answer.

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]

What was found. ok first, because it is the answer.

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: this runs from a click, and a dialog that crashes the screen is a worse answer than one that says what is wrong.

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 wins: the old custom_model boolean could disagree with the path beside it, and then which one won depended on which reader you asked.