armed.callbacks package#

Submodules#

armed.callbacks.aec_callbacks module#

Custom callbacks for autoencoder-classifiers.

armed.callbacks.aec_callbacks.compute_image_metrics(epoch: int, model, data_in, metadata: pandas.DataFrame, output_dir: str, output_idx: int = 0)#

Compute image metrics including brightness, contrast, sharpness, and SNR. Also create histograms comparing distributions of these metrics across clusters.

Parameters:
  • epoch (int) – epoch number

  • model (tf.keras.Model) – model

  • data_in (np.array or tuple of arrays) – input data

  • metadata (pd.DataFrame) – image metadata

  • output_dir (str) – path to output location

  • output_idx (int, optional) – Index of model outputs containing the image outputs. Defaults to 0.

Returns:

[description]

Return type:

[type]

armed.callbacks.aec_callbacks.make_compute_latents_callback(model, images: numpy.array, image_metadata: pandas.DataFrame, output_dir: str)#

Generate a callback function that calls the encoder on some images to create latent representations, then saves them to a .pkl file. The function also computes the Davies-Bouldin and Calinski-Harabasz clustering metrics on the latents and logs the results to a file. The generated function should be used with the LambdaCallback class from Keras to create the callback object.

Parameters:
  • model (tf.keras.Model) – encoder model

  • images (np.array) – batch of 8 images (8 x h x w x 1)

  • image_metadata (pd.DataFrame) – metadata table

  • output_dir (str) – output path

armed.callbacks.aec_callbacks.make_image_metrics_callback(model, data_in, metadata, output_dir, output_idx=0)#

Generate a callback function that computes image metrics including brightness, contrast, sharpness, and SNR. The generated function should be used with the LambdaCallback class from Keras to create the callback object.

Parameters:
  • model (tf.keras.Model) – model

  • data_in (np.array or tuple of arrays) – input data

  • metadata (pd.DataFrame) – image metadata

  • output_dir (str) – path to output location

  • output_idx (int, optional) – Index of model outputs containing the image outputs. Defaults to 0.

armed.callbacks.aec_callbacks.make_recon_figure_callback(images: numpy.array, model, output_dir: str, clusters: numpy.array | None = None, mixedeffects: bool = False)#

Generate a callback function that produces a figure with example reconstructions. The figure optionally includes the reconstructions with and without cluster-specific effects. The generated function should be used with the LambdaCallback class from Keras to create the callback object.

Parameters:
  • images (np.array) – batch of 8 images (8 x h x w x 1)

  • model (tf.keras.Model) – model

  • output_dir (str) – output path

  • clusters (np.array) – one-hot encoded cluster design matrix if needed by model (8 x n_clusters). Defaults to None

  • mixedeffects (bool) – include recons w/ and w/o random effects

armed.callbacks.segmentation module#

Custom Keras callbacks for segmentation models (currently unused)

class armed.callbacks.segmentation.SaveImagesCallback(*args: Any, **kwargs: Any)#

Bases: Callback

on_epoch_end(epoch, logs=None)#
class armed.callbacks.segmentation.SaveMultiModalImagesCallback(*args: Any, **kwargs: Any)#

Bases: Callback

on_epoch_end(epoch, logs=None)#

Module contents#

Custom callbacks