Entry Point¶
Train¶
Module to train a network using init files and a CLI.
-
deepreg.train.
build_config
(config_path: Union[str, List[str]], log_dir: str, exp_name: str, ckpt_path: str, max_epochs: int = - 1) → Tuple[Dict, str, str]¶ Function to initialise log directories, assert that checkpointed model is the right type and to parse the configuration for training.
- Parameters
config_path – list of str, path to config file
log_dir – path of the log directory
exp_name – name of the experiment
ckpt_path – path where model is stored.
max_epochs – if max_epochs > 0, use it to overwrite the configuration
- Returns
config: a dictionary saving configuration
exp_name: the path of directory to save logs
-
deepreg.train.
main
(args=None)¶ Entry point for train script.
- Parameters
args – arguments
-
deepreg.train.
train
(gpu: str, config_path: Union[str, List[str]], ckpt_path: str, num_workers: int = 1, gpu_allow_growth: bool = True, exp_name: str = '', log_dir: str = 'logs', max_epochs: int = - 1)¶ Function to train a model.
- Parameters
gpu – which local gpu to use to train.
config_path – path to configuration set up.
ckpt_path – where to store training checkpoints.
num_workers – number of cpu cores to be used, <=0 means not limited.
gpu_allow_growth – whether to allocate whole GPU memory for training.
log_dir – path of the log directory.
exp_name – experiment name.
max_epochs – if max_epochs > 0, will use it to overwrite the configuration.
Predict¶
Module to perform predictions on data using command line interface.
-
deepreg.predict.
build_config
(config_path: Union[str, List[str]], log_dir: str, exp_name: str, ckpt_path: str) → Tuple[Dict, str, str]¶ Function to create new directory to log directory to store results.
- Parameters
config_path – path of configuration files.
log_dir – path of the log directory.
exp_name – experiment name.
ckpt_path – path where model is stored.
- Returns
config, configuration dictionary.
exp_name, path of the directory for saving outputs.
-
deepreg.predict.
build_pair_output_path
(indices: list, save_dir: str) → Tuple[str, str]¶ Create directory for saving the paired data
- Parameters
indices – indices of the pair, the last one is for label
save_dir – directory of output
- Returns
save_dir, str, directory for saving the moving/fixed image
label_dir, str, directory for saving the rest outputs
-
deepreg.predict.
main
(args=None)¶ Entry point for predict script.
- Parameters
args –
-
deepreg.predict.
predict
(gpu: str, ckpt_path: str, split: str, batch_size: int, exp_name: str, config_path: Union[str, List[str]], num_workers: int = 1, gpu_allow_growth: bool = True, save_nifti: bool = True, save_png: bool = True, log_dir: str = 'logs')¶ Function to predict some metrics from the saved model and logging results.
- Parameters
gpu – which env gpu to use.
ckpt_path – where model is stored, should be like log_folder/save/ckpt-x.
split – train / valid / test, to define the split to be evaluated.
batch_size – int, batch size to perform predictions.
exp_name – name of the experiment.
config_path – to overwrite the default config.
num_workers – number of cpu cores to be used, <=0 means not limited.
gpu_allow_growth – whether to allocate whole GPU memory for training.
save_nifti – if true, outputs will be saved in nifti format.
save_png – if true, outputs will be saved in png format.
log_dir – path of the log directory.
-
deepreg.predict.
predict_on_dataset
(dataset: tensorflow.python.data.ops.dataset_ops.DatasetV2, fixed_grid_ref: tensorflow.python.framework.ops.Tensor, model: tensorflow.python.keras.engine.training.Model, save_dir: str, save_nifti: bool, save_png: bool)¶ Function to predict results from a dataset from some model
- Parameters
dataset – where data is stored
fixed_grid_ref – shape=(1, f_dim1, f_dim2, f_dim3, 3)
model – model to be used for prediction
save_dir – path to store dir
save_nifti – if true, outputs will be saved in nifti format
save_png – if true, outputs will be saved in png format
Warp¶
Module to warp a image with given ddf. A CLI tool is provided.
-
deepreg.warp.
main
(args=None)¶ Entry point for warp script.
- Parameters
args –
-
deepreg.warp.
shape_sanity_check
(image: numpy.ndarray, ddf: numpy.ndarray)¶ Verify image and ddf shapes are consistent and correct.
- Parameters
image – a numpy array of shape (m_dim1, m_dim2, m_dim3) or (m_dim1, m_dim2, m_dim3, ch)
ddf – a numpy array of shape (f_dim1, f_dim2, f_dim3, 3)
-
deepreg.warp.
warp
(image_path: str, ddf_path: str, out_path: str)¶ - Parameters
image_path – file path of the image file
ddf_path – file path of the ddf file
out_path – file path of the output