Overview
DigiPathAI uses TensorFlow with GPU acceleration to perform deep learning-based segmentation. Proper GPU configuration is essential for optimal performance and stability.CUDA Device Selection
By default, DigiPathAI uses GPU device 0. You can change which GPU to use by setting theCUDA_VISIBLE_DEVICES environment variable.
Single GPU
GPU device selection is configured in
Segmentation.py:62:Multiple GPUs
To use multiple GPUs (for parallel processing of multiple slides):CPU-Only Mode
To disable GPU and run on CPU only:TensorFlow GPU Configuration
Memory Growth
DigiPathAI enables GPU memory growth to prevent TensorFlow from allocating all available GPU memory at startup. This is configured inSegmentation.py:282-285:
Memory growth allows TensorFlow to allocate GPU memory as needed rather than reserving all available memory. This is crucial for running multiple processes or leaving memory for other applications.
Custom GPU Configuration
For advanced GPU configuration, you can modify the TensorFlow session config:Custom GPU Settings
Batch Size Tuning
Batch size significantly impacts GPU memory usage and processing speed. It’s configured as a parameter togetSegmentation().
Number of patches processed simultaneously on GPU.
Recommended Batch Sizes
| GPU Memory | Patch Size 256 | Patch Size 512 |
|---|---|---|
| 4 GB | 8-16 | 2-4 |
| 8 GB | 16-32 | 4-8 |
| 11 GB | 32-64 | 8-16 |
| 16 GB+ | 64-128 | 16-32 |
Adjusting Batch Size
Memory Management
Monitoring GPU Usage
Monitor GPU utilization and memory usage:Memory Optimization Tips
Reduce patch size
Reduce patch size
Smaller patches require less GPU memory but may affect segmentation quality:
Reduce number of workers
Reduce number of workers
Fewer data loading workers reduce CPU memory usage:The
num_workers parameter in get_prediction() defaults to 8. Reduce if experiencing memory issues:Clear GPU memory between runs
Clear GPU memory between runs
Explicitly clear TensorFlow session:
Multi-GPU Configuration
For processing multiple slides in parallel across multiple GPUs:Multi-GPU Processing
Requirements
CUDA Installation
DigiPathAI requires:- CUDA Toolkit 10.0 or later
- cuDNN 7.6 or later
- Compatible NVIDIA GPU (compute capability 3.5+)
TensorFlow GPU
Install TensorFlow with GPU support:DigiPathAI is built with TensorFlow 1.x. Ensure you install the GPU-enabled version compatible with your CUDA installation.
Troubleshooting
CUDA/cuDNN not found errors
CUDA/cuDNN not found errors
Ensure CUDA and cuDNN libraries are in your
LD_LIBRARY_PATH:Out of Memory (OOM) errors
Out of Memory (OOM) errors
- Reduce
batch_size - Reduce
patch_size - Enable memory growth (already enabled by default)
- Close other GPU applications
- Use a GPU with more memory
GPU not being utilized
GPU not being utilized
- Verify CUDA installation:
nvidia-smi - Check TensorFlow can see GPU:
- Ensure
CUDA_VISIBLE_DEVICESis set correctly - Check that you’re not running in
--viewer-onlymode
Slow processing despite GPU availability
Slow processing despite GPU availability
- Increase
batch_sizeif GPU memory allows - Increase
num_workersfor data loading - Reduce
stride_sizeto process fewer patches - Disable test-time augmentation if enabled
Source Reference
GPU configuration code is located in:Segmentation.py:62- CUDA device selectionSegmentation.py:282-285- TensorFlow GPU session configurationSegmentation.py:68- Batch size parameterSegmentation.py:71- Number of workers parameter