slideflow.model.tensorflow¶
This submodule contains Tensorflow-specific utility functions when working in the Tensorflow backend.
- load(path: str, method: str = 'weights', custom_objects: Dict[str, Any] | None = None, training: bool = False) Model [source]¶
Load a model trained with Slideflow.
- Parameters:
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 theparams.json
configuration file, build the model architecture, and then load weights from the given model withModel.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.
- Returns:
Loaded model.
- Return type:
tf.keras.models.Model
- 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.
- Parameters:
- Keyword Arguments:
- Returns:
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.
- Parameters:
model (tf.keras.models.Model) – Model built with Slideflow.
- Returns:
A tuple containing
tf.Tensor: Input tensor.
tf.Tensor: Post-convolutional layer output tensor.
tf.Tensor: Final model output tensor.