• Docs >
  • slideflow.model.tensorflow


This submodule contains Tensorflow-specific utility functions when working in the Tensorflow backend.

flatten(model: Model) Model[source]

Unwrapped then flattens a Tensorflow model.

load(path: str, method: str = 'weights', custom_objects: Dict[str, Any] | None = None, training: bool = False) Model[source]

Load a model trained with Slideflow.

  • path (str) – Path to saved model. Must be a model trained in Slideflow.

  • method (str) – Method to use when loading the model; either ‘full’ or ‘weights’. If ‘full’, will load the saved model with tf.keras.models.load_model(). If ‘weights’, will read the params.json configuration file, build the model architecture, and then load weights from the given model with Model.load_weights(). Loading with ‘full’ may improve compatibility across Slideflow versions. Loading with ‘weights’ may improve compatibility across hardware & environments.

  • custom_objects (dict, Optional) – Dictionary mapping names (strings) to custom classes or functions. Defaults to None.


Loaded model.

Return type:


log_manifest(train_tfrecords: List[str] | None = None, val_tfrecords: List[str] | None = None, *, labels: Dict[str, Any] | None = None, filename: str | None = None, remove_extension: bool = True) str[source]

Saves the training manifest in CSV format and returns as a string.

  • train_tfrecords (list(str)], optional) – List of training TFRecords. Defaults to None.

  • val_tfrecords (list(str)], optional) – List of validation TFRecords. Defaults to None.

Keyword Arguments:
  • labels (dict, optional) – TFRecord outcome labels. Defaults to None.

  • filename (str, optional) – Path to CSV file to save. Defaults to None.

  • remove_extension (bool, optional) – Remove file extension from slide names. Defaults to True.


Saved manifest in str format.

Return type:


unwrap(model: Model) Tuple[Tensor, Tensor, Tensor][source]

Unwraps a Tensorflow model built in Slideflow, returning the input tensor, post-convolutional output tensor, and final model output tensor.


model (tf.keras.models.Model) – Model built with Slideflow.


A tuple containing

tf.Tensor: Input tensor.

tf.Tensor: Post-convolutional layer output tensor.

tf.Tensor: Final model output tensor.