Overview
DigiPathAI provides advanced configuration options for fine-tuning segmentation quality and performance. These parameters affect the AI inference pipeline.Model Selection
DigiPathAI supports three deep learning architectures, and can use them individually or as an ensemble.Available Models
Select which neural network architecture to use for segmentation.Options:
dense- DenseNet-based architectureinception- Inception-based architecturedeeplabv3- DeepLab v3 architecture
Single Model Mode
Use a single model for faster inference:Single model mode is controlled by the
quick parameter. When quick=True, only the model specified by the model parameter is used (Segmentation.py:288-300).Ensemble Mode
Use all three models for best accuracy:Test-Time Augmentation (TTA)
Test-time augmentation applies transformations to input patches during inference and averages predictions for improved robustness.List of augmentation transformations to apply during inference.Allowed values:
FLIP_LEFT_RIGHT- Horizontal flipROTATE_90- 90° rotationROTATE_180- 180° rotationROTATE_270- 270° rotation
Basic TTA
Multiple Augmentations
No TTA (Default)
TTA processing is implemented in
Segmentation.py:95-99. The DEFAULT transformation is always included, and specified augmentations are concatenated to it.Performance Impact
| TTA Configuration | Relative Speed | Use Case |
|---|---|---|
| None | 1x (fastest) | Quick analysis, preliminary results |
| 1 augmentation | ~2x slower | Balanced accuracy/speed |
| 4 augmentations | ~5x slower | Maximum accuracy, final analysis |
Patch-Based Segmentation
Patch Size
Size of square patches extracted from the whole slide image for segmentation.
- Larger patches (512) capture more context but require more GPU memory
- Smaller patches (128) are faster but may miss larger patterns
- Models are trained on 256x256 patches (default)
Stride Size
Spacing between patch extraction locations. Smaller stride = more overlap = better quality but slower.
(patch_size - stride_size) / patch_size × 100%
| Patch Size | Stride Size | Overlap | Quality | Speed |
|---|---|---|---|---|
| 256 | 256 | 0% | Lower | Fastest |
| 256 | 128 | 50% | Good | Moderate |
| 256 | 64 | 75% | Better | Slower |
| 256 | 32 | 87.5% | Best | Slowest |
The stride-based patch extraction is implemented in
Segmentation.py:81-89 using the WSIStridedPatchDataset class with sampling_stride parameter.Mask Level Configuration
Pyramid level to use for mask generation.
-1 uses the highest resolution level.-1or0- Full resolution (slowest, highest quality)1- 2x downsampled2- 4x downsampled- Higher levels - Faster but lower resolution masks
Conditional Random Fields (CRF)
CRF post-processing refines segmentation boundaries using image information.Apply Conditional Random Fields post-processing to refine segmentation edges.
CRF post-processing code is present in
Segmentation.py:327-330 but is currently commented out. It uses the post_process_crf() helper function.When to Use CRF
✅ Use CRF when:- Segmentation boundaries need to be precise
- Working with well-stained, high-contrast images
- Processing time is not critical
- Speed is priority
- Image quality is poor
- Boundaries are already clean
Output Configuration
Save Paths
Path where the binary segmentation mask will be saved.
Path where the probability map will be saved (before thresholding).
Path where the uncertainty map (variance across predictions) will be saved.
Output Formats
All outputs are saved as pyramidal TIFF files with JPEG compression:- Probability Map - Continuous values [0-255] representing segmentation confidence
- Binary Mask - Thresholded mask (0 or 255) based on threshold=0.3
- Uncertainty Map - Variance across predictions, indicating confidence
Complete Configuration Example
Advanced Configuration
Tissue Type Modes
Tissue type for segmentation. Determines which pre-trained models to load.Options:
colon- Colorectal cancer (DigestPath dataset)liver- Liver cancer (PAIP dataset)breast- Breast cancer metastases (Camelyon dataset)
Model paths are configured in
Segmentation.py:232-278. Each tissue type has three model variants (inception, deeplabv3, densenet) automatically downloaded on first use.Performance Optimization
For Speed
Fast Configuration
For Quality
Quality Configuration
Troubleshooting
ValueError: Unknown model provided
ValueError: Unknown model provided
Ensure
model parameter is one of: 'dense', 'inception', or 'deeplabv3'.Source: Segmentation.py:300ValueError: Unknown mode found
ValueError: Unknown mode found
Ensure
mode parameter is one of: 'colon', 'liver', or 'breast'.Source: Segmentation.py:230Segmentation quality is poor
Segmentation quality is poor
- Try ensemble mode (
quick=False) - Enable test-time augmentation
- Reduce stride for more overlap
- Ensure correct tissue type mode is selected
Processing is very slow
Processing is very slow
- Use single model mode (
quick=True) - Disable TTA (
tta_list=None) - Increase stride to reduce patches
- Increase batch size if GPU memory allows
- Use lower mask level for coarser results
Source Reference
Advanced configuration parameters are defined in:Segmentation.py:192-225-getSegmentation()function signatureSegmentation.py:65-76-get_prediction()function signatureSegmentation.py:287-300- Model selection logicSegmentation.py:95-99- TTA list processing