CIL
CIL copied to clipboard
callbacks not a package and limited doc available
Description
import cil.optimisation.utilities.callbacks.Callback as Callback
leads to
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[62], line 1
----> 1 import cil.optimisation.utilities.callbacks.Callback as Callback
ModuleNotFoundError: No module named 'cil.optimisation.utilities.callbacks.Callback'; 'cil.optimisation.utilities.callbacks' is not a package
help(cil.optimisation.utilities.callbacks.Callback)
Is this expected?
Also, the docstring for this class gives no idea how this should work, e.g. what the signature is for the __call__ method.
From looking at Algorithm.py, I found out I have to do
from cil.optimisation.utilities.callbacks import Callback, ProgressCallback
Obvious? If so, sorry for the noise!
By looking at existing code (but not documentation), I was able to construct a callback that saves images
class SaveCallback(Callback):
def __init__(self, run_every=1):
super().__init__()
self.run_every = run_every
def __call__(self, algorithm):
if not hasattr(algorithm, 'saved_images'):
algorithm.saved_images = []
if (algorithm.iteration % self.run_every == 0):
algorithm.saved_images.append((algorithm.iteration, algorithm.get_output().clone()))
Seems to work ok.
import cil.optimisation.utilities.callbacks.Callback as Callback
where did you see this @KrisThielemans? It should indeed be:
from cil.optimisation.utilities.callbacks import Callback
FYI the docs are at https://tomographicimaging.github.io/CIL/nightly/optimisation/#callbacks.