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', orientation='lia', image_size=True, 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]])
orientation
(OrientationType)
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_as
str,Path Filename to give the image.
- data
np.ndarray,torch.Tensor Image data.
- orig
nib.analyze.SpatialImage Original Image.
- dtype
type,optional Data type to use for saving the image. If None, the original data type is used.
- save_as
- 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:
- subject
SubjectDirectory Subject directory object.
- subject
- Returns:
tuple[nib.analyze.SpatialImage,np.ndarray]Conformed image.
- get_prediction(image_name, orig_data, zoom, affine)[source]¶
Run and get prediction.
- Parameters:
- image_name
str Original image filename.
- orig_data
np.ndarray Original image data.
- zoom
np.ndarray,tuple Original zoom.
- affine
npt.NDArray[float] Original affine.
- image_name
- Returns:
np.ndarrayPredicted classes.
- pipeline_conform_and_save_orig(subjects)[source]¶
Pipeline for conforming and saving original images asynchronously.
- Parameters:
- subjects
SubjectList List of subjects to process.
- subjects
- 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_as
str,Path Filename to give the image.
- data
np.ndarray,torch.Tensor Image data.
- orig
nib.analyze.SpatialImage Original Image.
- dtype
type,optional Data type to use for saving the image. If None, the original data type is used.
- save_as
- set_model(plane)[source]¶
Set the current model for the specified plane.
- Parameters:
- plane
Plane The plane for which to set the current model.
- plane
- 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:
- Returns:
yacs.config.CfgNodeConfigurations for all planes.
- FastSurferCNN.run_prediction.make_parser()[source]¶
Create the argparse object.
- Returns:
argparse.ArgumentParserThe parser object.