transforms
orchard.data_handler.transforms
¶
Data Transformation Pipelines.
Defines image augmentation for training and normalization for validation/testing. Supports both RGB and Grayscale datasets with automatic channel promotion. Optimized for both CPU and GPU execution (torchvision v2).
get_augmentations_description(aug_cfg, img_size, mixup_alpha, ds_meta=None)
¶
Generates descriptive string of augmentations for logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aug_cfg
|
AugmentationConfig
|
Augmentation sub-configuration |
required |
img_size
|
int
|
Target image size for resized crop |
required |
mixup_alpha
|
float
|
MixUp alpha (0.0 to disable) |
required |
ds_meta
|
DatasetMetadata | None
|
Dataset metadata (if provided, respects domain flags) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Human-readable augmentation summary |
Source code in orchard/data_handler/transforms.py
get_pipeline_transforms(aug_cfg, img_size, ds_meta, *, force_rgb=True, norm_mean=None, norm_std=None)
¶
Constructs training and validation transformation pipelines.
Dynamically adapts to dataset characteristics (RGB vs Grayscale) and optionally promotes grayscale to 3-channel for pretrained-weight compatibility. Uses torchvision v2 transforms for improved CPU/GPU performance.
Pipeline Logic
- Convert to tensor format (ToImage + ToDtype)
- Promote 1-channel to 3-channel when
force_rgbis True and the dataset is native grayscale - Apply domain-aware augmentations (training only): geometric transforms disabled for anatomical datasets, color jitter reduced for texture-based datasets
- Normalize with dataset-specific statistics
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aug_cfg
|
AugmentationConfig
|
Augmentation sub-configuration |
required |
img_size
|
int
|
Target image size |
required |
ds_meta
|
DatasetMetadata
|
Dataset metadata (channels, domain flags) |
required |
force_rgb
|
bool
|
Promote grayscale datasets to 3-channel RGB |
True
|
norm_mean
|
tuple[float, ...] | None
|
Pre-computed normalization mean (from DatasetConfig). When None, computed from ds_meta + force_rgb. |
None
|
norm_std
|
tuple[float, ...] | None
|
Pre-computed normalization std (from DatasetConfig). When None, computed from ds_meta + force_rgb. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Compose, Compose]
|
tuple[v2.Compose, v2.Compose]: (train_transform, val_transform) |
Source code in orchard/data_handler/transforms.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |