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 CTGeometry; the operator is made from them) or any LIONOperator; kept as given, and asself.opto 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: aLIONParameterwith the algorithm’s settings, from the class’sdefault_parameters().reconstructtakes only the data, a starting imagex0andverbose(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
|
Base class of reconstructors (see the module docstring). |
- class LION.reconstructors.LIONreconstructor.LIONReconstructor(operator, model=None, parameters=None)[source]¶
Bases:
ABCBase 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 byload(with its model) orinstantiate(without).
- classmethod load(fname, *, allow=())[source]¶
The reconstructor
fname(a filesavewrote) 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 tofname’s folder.allow: as inLION.utils.spec.build. The reconstructor keeps its file assource_file.
- classmethod instantiate(source, model=None, *, allow=(), **arguments)[source]¶
The reconstructor
sourcedescribes: 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.argumentsreplace recorded ones. Called onLIONReconstructorit makes the class the spec names; on a reconstructor class, that class.