Skip to content

callback_factories

callback_factories

Module for all callback factories

Classes

CallbackFactory

Bases: ABC

ABC for creating callbacks

Functions
create_callback abstractmethod
create_callback(exp_context)

Creates a callback from the given experiment context

Source code in niceml/dlframeworks/keras/callbacks/callback_factories.py
@abstractmethod
def create_callback(self, exp_context: ExperimentContext):
    """Creates a callback from the given experiment context"""

CamCallbackFactory

CamCallbackFactory(images)

Bases: CallbackFactory

Callback factory for a cam callback

Source code in niceml/dlframeworks/keras/callbacks/callback_factories.py
def __init__(self, images: List[str]):
    self.images = images
Functions
create_callback
create_callback(exp_context)

Factory method to initialize GRID-CAM callback

Parameters will be set by parameters.yaml

Examples:

callbacks: - type: niceml.callbacks.callback_factories.cam_callback_factory params: image_location: *experiment_path images: - /path/to/data/train/Lemon/r_304_100.jpg - /path/to/data/train/Kiwi/2_100.jpg - /path/to/data/train/Walnut/3_100.jpg - /path/to/data/train/Watermelon/2_100.jpg

Parameters:

  • image_location

    path to experiment folder

  • images

    list of image paths

Source code in niceml/dlframeworks/keras/callbacks/callback_factories.py
def create_callback(self, exp_context: ExperimentContext):
    """
    Factory method to initialize GRID-CAM callback

    Parameters will be set by parameters.yaml

    Examples:
    callbacks:
        - type: niceml.callbacks.callback_factories.cam_callback_factory
        params:
            image_location: *experiment_path
            images:
                - /path/to/data/train/Lemon/r_304_100.jpg
                - /path/to/data/train/Kiwi/2_100.jpg
                - /path/to/data/train/Walnut/3_100.jpg
                - /path/to/data/train/Watermelon/2_100.jpg

    Args:
        image_location: path to experiment folder
        images: list of image paths

    """
    filepath = join(exp_context.filepath, "cam")
    filepath = subs_path_and_create_folder(
        filepath, exp_context.short_id, exp_context.run_id
    )

    Path(filepath).mkdir(exist_ok=True, parents=False)

    # pylint: disable=import-outside-toplevel
    from niceml.dlframeworks.keras.callbacks.cam_callback import CamCallback

    return CamCallback(output_dir=filepath, images=self.images)

InitCallbackFactory

InitCallbackFactory(callback)

Bases: CallbackFactory

Creates a callback which doesn't need any experiment specific parameters

Source code in niceml/dlframeworks/keras/callbacks/callback_factories.py
def __init__(self, callback: Any):
    self.callback = callback

LoggingOutputCallbackFactory

LoggingOutputCallbackFactory(filename='train_logs.csv')

Bases: CallbackFactory

Creates a callback that logs the metrics to a csv file

Source code in niceml/dlframeworks/keras/callbacks/callback_factories.py
def __init__(self, filename: str = "train_logs.csv"):
    self.filename = filename

ModelCallbackFactory

ModelCallbackFactory(model_subfolder, **kwargs)

Bases: CallbackFactory

Creates the model checkpoint callback

Source code in niceml/dlframeworks/keras/callbacks/callback_factories.py
def __init__(self, model_subfolder: str, **kwargs):
    self.kwargs = kwargs
    self.model_subfolder = model_subfolder

Functions