transforms
The augmentation transforms related classes and helpers.
kelp.nn.data.transforms.MinMaxNormalize
Bases: Module
Min-Max normalization transform that uses provided min and max per-channel values for image transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_vals |
Tensor
|
A Tensor of min values per-channel. |
required |
max_vals |
Tensor
|
A Tensor of max values per-channel. |
required |
Source code in kelp/nn/data/transforms.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
kelp.nn.data.transforms.PerSampleMinMaxNormalize
Bases: Module
A per-sample normalization transform that will calculate min and max per-channel on the fly.
Source code in kelp/nn/data/transforms.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
kelp.nn.data.transforms.PerSampleMinMaxNormalize.forward
Runs the normalization transform for specified batch of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The batch of images. |
required |
Source code in kelp/nn/data/transforms.py
47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
kelp.nn.data.transforms.PerSampleQuantileNormalize
Bases: Module
A per-sample normalization transform that will calculate min and max per-channel on the fly using provided quantile values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
q_low |
float
|
The lower quantile value. |
required |
q_high |
float
|
The upper quantile value. |
required |
Source code in kelp/nn/data/transforms.py
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 |
|
kelp.nn.data.transforms.PerSampleQuantileNormalize.forward
Runs the normalization transform for specified batch of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The batch of images. |
required |
Source code in kelp/nn/data/transforms.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
kelp.nn.data.transforms.RemoveNaNs
Bases: Module
Removes NaN values from the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_vals |
Tensor
|
The min values per-channel to use when removing NaNs and neg-Inf. |
required |
max_vals |
Tensor
|
The min values per-channel to use when removing positive-Inf. |
required |
Source code in kelp/nn/data/transforms.py
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 |
|
kelp.nn.data.transforms.RemoveNaNs.forward
Runs the transform for specified batch of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The batch of images. |
required |
Source code in kelp/nn/data/transforms.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
kelp.nn.data.transforms.RemovePadding
Bases: Module
Removes specified padding from the input tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_size |
int
|
The size of the target image after padding removal. |
required |
padded_image_size |
int
|
The size of the padded image before padding removal. |
required |
args |
Any
|
Arguments passed to super class. |
()
|
kwargs |
Any
|
Keyword arguments passed to super class. |
{}
|
Source code in kelp/nn/data/transforms.py
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 |
|
kelp.nn.data.transforms.RemovePadding.forward
Runs the transform for specified batch of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The batch of images. |
required |
Source code in kelp/nn/data/transforms.py
146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
kelp.nn.data.transforms.build_append_index_transforms
Build an append index transforms based on specified spectral indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectral_indices |
List[str]
|
A list of spectral indices to use. |
required |
Source code in kelp/nn/data/transforms.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
kelp.nn.data.transforms.min_max_normalize
Runs min-max normalization on the input array by calculating min and max per-channel values on the fly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr |
ndarray
|
The array to normalize. |
required |
Source code in kelp/nn/data/transforms.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
kelp.nn.data.transforms.quantile_min_max_normalize
Runs min-max quantile normalization on the input array by calculating min and max per-channel values on the fly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
The array to normalize. |
required |
q_lower |
float
|
The lower quantile. |
0.01
|
q_upper |
float
|
The upper quantile. |
0.99
|
Source code in kelp/nn/data/transforms.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
kelp.nn.data.transforms.resolve_normalization_stats
Resolves normalization stats based on specified bands to use.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_stats |
Dict[str, Dict[str, float]]
|
The full per-band dataset statistics. |
required |
bands_to_use |
List[str]
|
The list of band names to use. |
required |
Source code in kelp/nn/data/transforms.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
kelp.nn.data.transforms.resolve_normalization_transform
Resolves the normalization transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band_stats |
BandStats
|
The band statistics. |
required |
normalization_strategy |
Literal['min-max', 'quantile', 'per-sample-min-max', 'per-sample-quantile', 'z-score']
|
The normalization strategy. |
'quantile'
|
Source code in kelp/nn/data/transforms.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
kelp.nn.data.transforms.resolve_resize_transform
Resolves the input image and mask resize transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_or_mask |
Literal['image', 'mask']
|
Indicates if the transform is for an image or a mask. |
required |
resize_strategy |
Literal['pad', 'resize']
|
The resize strategy to use. |
'pad'
|
image_size |
int
|
The size of the resized image. |
352
|
interpolation |
Literal['nearest', 'nearest-exact', 'bilinear', 'bicubic']
|
The interpolation method to use for the "resize" strategy. |
'nearest'
|
Source code in kelp/nn/data/transforms.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
kelp.nn.data.transforms.resolve_transforms
Resolves batch augmentation transformations to be used based on specified configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectral_indices |
List[str]
|
The list of spectral indices to use. |
required |
band_index_lookup |
Dict[str, int]
|
The dictionary mapping band name to index in the input tensor. |
required |
band_stats |
BandStats
|
The band statistics to use. |
required |
mask_using_qa |
bool
|
A flag indicating whether to mask spectral indices with QA band. |
required |
mask_using_water_mask |
bool
|
A flag indicating whether to mask spectral indices with DEM Water Mask. |
required |
normalization_transform |
Union[_AugmentationBase, Module]
|
A normalization transformation. |
required |
stage |
Literal['train', 'val', 'test', 'predict']
|
A literal indicating the stage to use. One of ["train", "val", "test", "predict"]. |
required |
Source code in kelp/nn/data/transforms.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|