scxpand.util.inference_utils#
Core inference functions for scXpand models.
This module contains only the core inference functionality: - Model loading - Running inference on data - Environment setup
Higher-level orchestration is handled by scxpand.core.prediction. I/O operations are handled by scxpand.util.io. Evaluation logic is handled by scxpand.core.evaluation.
Functions
|
Load a trained model from disk. |
|
Run inference using a trained model. |
|
Setup the inference environment by loading data format, model, and determining device. |
- scxpand.util.inference_utils.load_model(model_type, model_path, device)#
Load a trained model from disk.
- Parameters:
- Return type:
- Returns:
Loaded model (scikit-learn estimator or PyTorch module)
- Raises:
ValueError – If model_type is not supported
- scxpand.util.inference_utils.run_model_inference(model_type, model, data_format, adata=None, data_path=None, device=None, batch_size=1024, num_workers=0, eval_row_inds=None)#
Run inference using a trained model.
This is the internal inference function that handles the actual model execution. For the public API, use scxpand.run_inference() instead.
- Parameters:
model (
BaseEstimator|Module) – Trained model instancedata_format (
DataFormat) – Data format specification for preprocessingadata (
AnnData|None(default:None)) – In-memory AnnData object (alternative to data_path)data_path (
str|Path|None(default:None)) – Path to data file (alternative to adata)device (
device|str|None(default:None)) – Device for computation (neural networks only)batch_size (
int(default:1024)) – Batch size for inferencenum_workers (
int(default:0)) – Number of workers for data loadingeval_row_inds (
ndarray|None(default:None)) – Specific cell indices to process (None for all)
- Return type:
- Returns:
Array of prediction probabilities
- Raises:
ValueError – If neither adata nor data_path is provided, or if model_type is unsupported
- scxpand.util.inference_utils.setup_inference_environment(model_type, model_path)#
Setup the inference environment by loading data format, model, and determining device.
- Parameters:
- Return type:
tuple[DataFormat,BaseEstimator|Module,device|str]- Returns:
Tuple of (data_format, model, device)
- Raises:
FileNotFoundError – If data format file is not found