degree1_inference_utils#

This module provides functionality to run inference on 3D patches extracted from a 3D image,

The main user functions are run_inference, which extracts patches centered on degree=1 graph vertices, and update_graph_properties, which updates the graph with new properties based on the inference results.

class PatchDataset(vertices_df, image, shape=(30, 30, 30))[source]#

Bases: Dataset

Dataset for extracting 3D patches centered on degree=1 graph vertices.

filter_valid_vertices()[source]#
class Swin3DModel(num_classes=2)[source]#

Bases: Module

Swin3D-based binary classifier for degree=1 tip cells and interrupted vessels.

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_default_model_path(weights_file_name='swin3d_s_weights.pth')[source]#

Get the default path to the pre-trained Swin3D model weights.

Parameters:

weights_file_name (str) – Name of the weights file. Default is “swin3d_s_weights.pth”.

Returns

str

Path to the pre-trained model weights.

load_model(weights_path)[source]#

Load the Swin3D model with pre-trained weights.

Parameters:

weights_path (str or Path) – Path to the model weights file.

Returns

Swin3DModel

An instance of the Swin3DModel with loaded weights.

run_inference(image, vertices_df, model_weights, patch_shape=(30, 30, 30), batch_size=16)[source]#

Run inference on patches centered on degree=1 graph vertices.

Parameters:
  • image (np.ndarray) – The 3D image from which to extract patches.

  • vertices_df (pd.DataFrame) – DataFrame containing vertex id, coordinates and degrees.

  • model_weights (str or Path) – Path to the model weights file.

  • patch_shape (tuple) – Shape of the patches to extract around each vertex.

  • batch_size (int) – Batch size for inference.

update_graph_properties(graph, scores_df, output_graph_path, threshold=0.8)[source]#

Updating the graph with two new properties: tip_cell_score and tip_cell_prediction

Parameters:
  • graph (ClearMap.Analysis.Graphs.GraphGt) – The graph to update with new properties.

  • scores_df (pd.DataFrame) – DataFrame containing vertex IDs and their corresponding tip cell scores. # FIXME: check other columns

  • output_graph_path (str or Path) – Path to save the updated graph with new properties.

  • threshold (float) – Threshold for classifying a vertex as a tip cell. Default is 0.8.