FastSurferCNN.run_prediction

This is the FastSurfer/run_prediction.py script, the backbone for whole brain segmentation.

Usage:

See Also

FastSurferCNN: run_prediction.py run_prediction.py --help

class FastSurferCNN.run_prediction.RunModelOnData(lut, ckpt_ax=None, ckpt_sag=None, ckpt_cor=None, cfg_ax=None, cfg_sag=None, cfg_cor=None, device='auto', viewagg_device='auto', threads=1, batch_size=1, vox_size='min', async_io=False, conform_to_1mm_threshold=0.95)[source]

Run the model prediction on given data.

Attributes

vox_size

(float, ‘min’)

current_plane

(str)

models

(Dict[str, Inference])

view_ops

(Dict[str, Dict[str, Any]])

conform_to_1mm_threshold

(float, optional) threshold until which the image will be conformed to 1mm res

Methods

__init__()

Construct object.

set_and_create_outdir()

Sets and creates output directory.

conform_and_save_orig()

Saves original image.

set_subject()

Setter.

get_subject_name()

Getter.

set_model()

Setter.

run_model()

Calculates prediction.

get_img()

Getter.

save_img()

Saves image as file.

set_up_model_params()

Setter.

get_num_classes()

Getter.

async_save_img(save_as, data, orig, dtype=None)[source]

Save the image asynchronously and return a concurrent.futures.Future to track, when this finished.

Parameters:
save_asstr, Path

Filename to give the image.

dataUnion[np.ndarray, torch.Tensor]

Image data.

orignib.analyze.SpatialImage

Original Image.

dtypetype, optional

Data type to use for saving the image. If None, the original data type is used.

Returns:
Future[None]

A Future object to synchronize (and catch/handle exceptions in the save_img method).

conform_and_save_orig(subject)[source]

Conform and saves original image.

Parameters:
subjectSubjectDirectory

Subject directory object.

Returns:
tuple[nib.analyze.SpatialImage, np.ndarray]

Conformed image.

get_num_classes()[source]

Return the number of classes.

Returns:
int

The number of classes.

get_prediction(image_name, orig_data, zoom)[source]

Run and get prediction.

Parameters:
image_namestr

Original image filename.

orig_datanp.ndarray

Original image data.

zoomnp.ndarray, tuple

Original zoom.

Returns:
np.ndarray

Predicted classes.

pipeline_conform_and_save_orig(subjects)[source]

Pipeline for conforming and saving original images asynchronously.

Parameters:
subjectsSubjectList

List of subjects to process.

Yields:
tuple[SubjectDirectory, tuple[nib.analyze.SpatialImage, np.ndarray]]

Subject directory and a tuple with the image and its data.

save_img(save_as, data, orig, dtype=None)[source]

Save image as a file.

Parameters:
save_asstr, Path

Filename to give the image.

datanp.ndarray, torch.Tensor

Image data.

orignib.analyze.SpatialImage

Original Image.

dtypetype, optional

Data type to use for saving the image. If None, the original data type is used (Default value = None).

set_model(plane)[source]

Set the current model for the specified plane.

Parameters:
planePlane

The plane for which to set the current model.

set_up_model_params(plane, cfg, ckpt)[source]

Set up the model parameters from the configuration and checkpoint.

property pool

Return, and maybe create the objects executor object (with the number of threads specified in __init__).

FastSurferCNN.run_prediction.args2cfg(cfg_ax=None, cfg_cor=None, cfg_sag=None, batch_size=1)[source]

Extract the configuration objects from the arguments.

Parameters:
cfg_axstr, optional

The path to the axial network YAML config file.

cfg_corstr, optional

The path to the coronal network YAML config file.

cfg_sagstr, optional

The path to the sagittal network YAML config file.

batch_sizeint, default=1

The batch size for the network.

Returns:
yacs.config.CfgNode

Configurations for all planes.

FastSurferCNN.run_prediction.make_parser()[source]

Create the argparse object.

Returns:
argparse.ArgumentParser

The parser object.

FastSurferCNN.run_prediction.set_up_cfgs(cfg_file, batch_size=1)[source]

Set up configuration.

Sets up configurations with given arguments inside the yaml file.

Parameters:
cfg_filePath, str

Path to yaml file of configurations.

batch_sizeint, default=1

The batch size to use.

Returns:
yacs.config.CfgNode

Node of configurations.