_preffect.py module

class _preffect.Preffect(forward_log, existing_session=False, configs=None)

Bases: object

extract_batch(batches, idx)

Extracts a single batch from the given batches dictionary based on the specified index.

Parameters:
  • batches (Dict[str, List[Any]]) -- A dictionary where each key maps to a list or array of batched data.

  • idx (int) -- The index of the data to extract from each batch list in the batches dictionary.

Returns:

A dictionary containing the extracted data for each key in the input batches dictionary. The keys remain the same, but the values are the data items at the specified index.

Return type:

Dict[str, Any]

find_inference_in_register(ir_name)

Retrieves an inference object from the inference dictionary based on its name.

This method searches the internal dictionary that stores inference objects and returns the object associated with the given name if it exists. If no such object exists, it returns None.

Parameters:

ir_name (str) -- The name of the inference object to retrieve.

Returns:

The inference object associated with ir_name if it exists in the dictionary; otherwise, None.

Return type:

Optional[Any]

prep_from_existing_session(configs)

Restores the Preffect object from a saved session file.

Parameters:

configs (dict) -- Configuration dictionary containing necessary paths and settings, which should include keys for 'output_path' and 'input_existing_session' to construct the file path.

Raises:

PreffectError -- If an error occurs while trying to restore the session from the file, which could be due to a missing file, corrupted data, or incompatible configurations.

prep_new_session(configs, forward_log)

Prepares a new session for training by setting up datasets, model, optimizer, and other configurations necessary for training and validation.

Parameters:
  • configs (dict) -- Configuration parameters including dataset paths, model settings, training parameters, and device settings.

  • forward_log (logging.Logger) -- Logger used for recording operational messages and errors during the setup process.

Raises:

Exception -- Raises an exception if there are misconfigurations, file path errors, or other issues during the initialization of datasets or model components.

save(fname=None)

Saves the FFPE_dataset and trained model to a file on disk.

Parameters:

fname (str, optional) -- The filename under which to save the model. If not specified, the model is saved under the 'input_existing_session' specified in the configuration concatenated with '.pth'. The file is saved in the directory specified by 'output_path' in the configuration.

train(forward_log)

This function initializes the model, prepares data loaders for training and validation sets, and performs training of VAE model for FFPE dataset.

Parameters:

forward_log (logging.Logger) -- Logger object used for logging training progress and metrics.

Raises:

AssertionError -- If the configuration sanity checks fail.