LION.reconstructors.LIONreconstructor

The base class of reconstructors: methods that reconstruct with a trained model (e.g. a denoiser as a prior, a learned regulariser) inside an algorithm.

A reconstructor is made with everything that decides its result, then run:

pnp = PnP(operator, model, parameters) # parameters: PnP.default_parameters() images = pnp.reconstruct(measurements)

  • operator: operator parameters (e.g. a CT Geometry; the operator is made from them) or any LION Operator; kept as given, and as self.op to compute with;

  • model: the trained network (or any function of an image). Optional: a reconstructor can be made without one (instantiate) and given it later (reconstructor.model = model); running it without one is an error;

  • parameters: a LIONParameter with the algorithm’s settings, from the class’s default_parameters(). reconstruct takes only the data, a starting image x0 and verbose (how much progress is shown), so a reconstructor with its parameters is one method, recorded as such (LION.evaluation).

Its spec (LION.utils.spec) holds the operator and the parameters, not the model: a model’s spec would make it with new weights. Records of an evaluation keep the model’s identity (spec and weights hash) next to it, and instantiate(source, model) checks the model given against it.

reconstructor.save(file) writes its own record, file.json: its spec, the file its model was loaded from (LIONmodel.load) and the model’s weights hash, and the environment. The weights stay in the model’s file. LIONReconstructor.load(file) makes it again with that model; instantiate(file) makes it without one (give it another model).

A new reconstructor derives from this class, defines default_parameters() and reconstruct_sample(y, x0, verbose), and reads its settings from self.parameters. reconstruct_sample shows a progress bar over its iterations when verbose >= 1.

Classes

LIONReconstructor(operator[, model, parameters])

Base class of reconstructors (see the module docstring).


class LION.reconstructors.LIONreconstructor.LIONReconstructor(operator, model=None, parameters=None)[source]

Bases: ABC

Base class of reconstructors (see the module docstring).

static default_parameters()[source]

The algorithm’s settings (none here; reconstructors define theirs).

initial_guess(y)[source]

Where the algorithm starts for measurements y: the parameters’ initial_reconstruction(y, op). Its default, "default", is the operator’s default reconstruction (FDK for CT).

reconstruct(y, x0=None, verbose=1)[source]

Reconstruct measurements y: one sample (the operator’s range shape) or a batch of them, each on its own. x0: the starting image(s), where the algorithm takes one.

verbose: 0, nothing shown; 1 (default), one progress bar: over the samples of a batch, or over the iterations of one sample; 2, also the iterations of each sample of a batch.

abstract reconstruct_sample(y, x0, verbose)[source]

Reconstruct one measurement, with the settings in self.parameters.

spec_kwargs()[source]

The spec’s arguments: the operator and the parameters, not the model (a model’s spec would make it with new weights; see the module docstring).

save(fname)[source]

Write this reconstructor’s record to fname (.json): its spec (operator and parameters), its model by the file it was loaded from and its weights hash (a model made in the script: only the hash; a function: its spec), and the environment. Made again by load (with its model) or instantiate (without).

classmethod load(fname, *, allow=())[source]

The reconstructor fname (a file save wrote) describes, with its model loaded from the recorded file (a warning if its weights changed since). A model that wasn’t loaded from a file can’t be: then it has no model (a warning; give it one). A model file given by a relative path is relative to fname’s folder. allow: as in LION.utils.spec.build. The reconstructor keeps its file as source_file.

classmethod instantiate(source, model=None, *, allow=(), **arguments)[source]

The reconstructor source describes: its file (save), its spec, or a test record (LION.evaluation) of it, or that record’s file. model: the trained model to use (optional: set it later with .model = ...); with a file or a test record, a warning if its weights aren’t the recorded ones. arguments replace recorded ones. Called on LIONReconstructor it makes the class the spec names; on a reconstructor class, that class.

classmethod parameters_from_file(source, *, allow=())[source]

What default_parameters() gives, as source (as in instantiate) recorded it: the algorithm’s settings, to change and make the reconstructor with (PnP(operator, model, parameters)).

static cite(cite_format='bib')[source]

Where the reconstructor comes from: its paper’s citation, BibTeX (“bib”) or “MLA” (LION.utils.citation); None if it has none. Reconstructors from a paper define it.