HypVINN.inference¶
- class HypVINN.inference.Inference(cfg, threads=-1, async_io=False, device='auto', viewagg_device='auto')[source]¶
Class for running inference on a single subject.
Attributes
model
(torch.nn.Module) The model to use for inference.
model_name
(str) The name of the model.
Methods
setup_model(cfg)
Set up the model.
- eval(val_loader, pred_prob, out_scale=None)[source]¶
Evaluate the model on a HypVINN dataset.
This method runs the model in evaluation mode on a HypVINN Dataset. It iterates over the given dataset and computes the model’s predictions.
- Parameters:
- val_loader
DataLoader
The DataLoader for the validation set.
- pred_prob
torch.Tensor
The tensor to update with the prediction probabilities.
- out_scale
float
,optional
The scale factor for the output. Default is None.
- val_loader
- Returns:
- pred_prob:
torch.Tensor
The updated prediction probabilities.
- pred_prob:
- get_cfg()[source]¶
Get the configuration node.
This method returns the configuration node used in the Inference instance.
- Returns:
yacs.config.CfgNode
The configuration node containing the parameters for the model.
- get_device()[source]¶
Get the device.
This method returns the device and view aggregation device used in the Inference instance.
- Returns:
tuple
The device and view aggregation device.
- get_model_height()[source]¶
Get the model height.
This method returns the height of the model defined in the model configuration.
- Returns:
int
The height of the model.
- get_model_width()[source]¶
Get the model width.
This method returns the width of the model defined in the model configuration.
- Returns:
int
The width of the model.
- get_modelname()[source]¶
Get the name of the model.
This method returns the name of the model used in the Inference instance.
- Returns:
str
The name of the model.
- get_num_classes()[source]¶
Get the number of classes.
This method returns the number of classes defined in the model configuration.
- Returns:
int
The number of classes.
- get_plane()[source]¶
Get the plane.
This method returns the plane defined in the data configuration.
- Returns:
str
The plane.
- load_checkpoint(ckpt)[source]¶
Load a model checkpoint.
This method loads a model checkpoint from a .pth file containing a state dictionary of a model.
- Parameters:
- ckpt
str
The path to the checkpoint file. The checkpoint file should be a .pth file containing a state dictionary of a model.
- ckpt
- run(subject_name, modalities, orig_zoom, pred_prob, out_res=None, mode='t1t2')[source]¶
Run the inference process on a single subject.
This method sets up the HypVINN DataLoader for the subject, runs the model in evaluation mode on the subject’s data, and returns the updated prediction probabilities.
- Parameters:
- subject_name
str
The name of the subject.
- modalities
ModalityDict
The modalities of the subject.
- orig_zoom
npt.NDArray
[float
] The original zoom of the subject.
- pred_prob
torch.Tensor
The tensor to update with the prediction probabilities.
- out_res
float
,optional
The resolution of the output. Default is None.
- mode
ModalityMode
, default=”t1t2” The mode of the modalities. Default is ‘t1t2’.
- subject_name
- Returns:
- pred_prob:
torch.Tensor
The updated prediction probabilities.
- pred_prob:
- set_cfg(cfg)[source]¶
Set the configuration node.
- Parameters:
- cfg
yacs.config.CfgNode
The configuration node containing the parameters for the model.
- cfg