Transforms
KeypointTransform
Bases: object
Base class for all transforms for keypoints augmnetation. All transforms subclassing it should implement call method which takes image, mask and keypoints as input and returns transformed image, mask and keypoints.
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
__call__(image, mask, joints, areas, bboxes)
abstractmethod
Apply transformation to image, mask and keypoints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
Input image of [H,W,3] shape |
required |
mask |
np.ndarray
|
Numpy array of [H,W] shape, where zero values are considered as ignored mask (not contributing to the loss) |
required |
joints |
np.ndarray
|
Numpy array of [NumInstances, NumJoints, 3] shape. Last dimension contains (x,y,visibility) for each joint. |
required |
areas |
Optional[np.ndarray]
|
(Optional) Numpy array of [N] shape with area of each instance |
required |
bboxes |
Optional[np.ndarray]
|
(Optional) Numpy array of [N,4] shape with bounding box of each instance (XYWH) |
required |
Returns:
Type | Description |
---|---|
Tuple[np.ndarray, np.ndarray, np.ndarray, Optional[np.ndarray], Optional[np.ndarray]]
|
(image, mask, joints) |
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
KeypointsImageNormalize
Bases: KeypointTransform
Normalize image with mean and std. Note this transform should come after KeypointsImageToTensor since it operates on torch Tensor and not numpy array.
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
KeypointsImageToTensor
Bases: KeypointTransform
Convert image from numpy array to tensor and permute axes to [C,H,W]. This function also divides image by 255.0 to convert it to [0,1] range.
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
65 66 67 68 69 70 71 72 73 |
|
KeypointsLongestMaxSize
Bases: KeypointTransform
Resize image, mask and joints to ensure that resulting image does not exceed max_sizes (rows, cols).
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 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 235 236 |
|
__init__(max_height, max_width, interpolation=cv2.INTER_LINEAR, prob=1.0)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_sizes |
(rows, cols) - Maximum size of the image after resizing |
required | |
interpolation |
int
|
Used interpolation method for image |
cv2.INTER_LINEAR
|
prob |
float
|
Probability of applying this transform |
1.0
|
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
185 186 187 188 189 190 191 192 193 194 195 |
|
KeypointsPadIfNeeded
Bases: KeypointTransform
Pad image and mask to ensure that resulting image size is not less than output_size
(rows, cols).
Image and mask padded from right and bottom, thus joints remains unchanged.
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
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 |
|
__init__(min_height, min_width, image_pad_value, mask_pad_value)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_size |
Desired image size (rows, cols) |
required | |
image_pad_value |
int
|
Padding value of image |
required |
mask_pad_value |
float
|
Padding value for mask |
required |
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
246 247 248 249 250 251 252 253 254 255 256 |
|
KeypointsRandomAffineTransform
Bases: KeypointTransform
Apply random affine transform to image, mask and joints.
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
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 300 301 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 332 333 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 366 367 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 |
|
__call__(image, mask, joints, areas, bboxes)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
(np.ndarray) Image of shape [H,W,3] |
required |
mask |
np.ndarray
|
Single-element array with mask of [H,W] shape. |
required |
joints |
np.ndarray
|
Single-element array of joints of [Num instances, Num Joints, 3] shape. Semantics of last channel is: x, y, joint index (?) |
required |
area |
Area each instance occipy: [Num instances, 1] |
required |
Returns:
Type | Description |
---|---|
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
__init__(max_rotation, min_scale, max_scale, max_translate, image_pad_value, mask_pad_value, prob=0.5)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_rotation |
float
|
Max rotation angle in degrees |
required |
min_scale |
float
|
Lower bound for the scale change. For +- 20% size jitter this should be 0.8 |
required |
max_scale |
float
|
Lower bound for the scale change. For +- 20% size jitter this should be 1.2 |
required |
max_translate |
float
|
Max translation offset in percents of image size |
required |
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
KeypointsRandomHorizontalFlip
Bases: KeypointTransform
Flip image, mask and joints horizontally with a given probability.
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
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 |
|
__init__(flip_index, prob=0.5)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flip_index |
List[int]
|
Indexes of keypoints on the flipped image. When doing left-right flip, left hand becomes right hand. So this array contains order of keypoints on the flipped image. This is dataset specific and depends on how keypoints are defined in dataset. |
required |
prob |
float
|
Probability of flipping |
0.5
|
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
98 99 100 101 102 103 104 105 106 107 |
|
KeypointsRandomVerticalFlip
Bases: KeypointTransform
Flip image, mask and joints vertically with a given probability.
Source code in V3_1/src/super_gradients/training/transforms/keypoint_transforms.py
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 173 174 175 176 |
|
DetectionHSV
Bases: DetectionTransform
Detection HSV transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prob |
float
|
Probability to apply the transform. |
required |
hgain |
float
|
Hue gain. |
0.5
|
sgain |
float
|
Saturation gain. |
0.5
|
vgain |
float
|
Value gain. |
0.5
|
bgr_channels |
Channel indices of the BGR channels- useful for images with >3 channels, or when BGR channels are in different order. |
(0, 1, 2)
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
|
DetectionHorizontalFlip
Bases: DetectionTransform
Horizontal Flip for Detection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prob |
float
|
Probability of applying horizontal flip |
required |
max_targets |
int
|
Max objects in single image, padding target to this size in case of empty image. |
120
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
|
DetectionImagePermute
Bases: DetectionTransform
Permute image dims. Useful for converting image from HWC to CHW format.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
|
__init__(dims=(2, 0, 1))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dims |
Tuple[int, int, int]
|
Specify new order of dims. Default value (2, 0, 1) suitable for converting from HWC to CHW format. |
(2, 0, 1)
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
723 724 725 726 727 728 729 |
|
DetectionMixup
Bases: DetectionTransform
Mixup detection transform
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
Union[int, Tuple[int, int], None]
|
Input dimension. |
required |
mixup_scale |
tuple
|
Scale range for the additional loaded image for mixup. |
required |
prob |
float
|
Probability of applying mixup. |
1.0
|
enable_mixup |
bool
|
Whether to apply mixup at all (regardless of prob). |
True
|
flip_prob |
float
|
Probability to apply horizontal flip to the additional sample. |
0.5
|
border_value |
int
|
Value for filling borders after applying transform. |
114
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
|
DetectionMosaic
Bases: DetectionTransform
DetectionMosaic detection transform
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
Union[int, Tuple[int, int]]
|
Input dimension. |
required |
prob |
float
|
Probability of applying mosaic. |
1.0
|
enable_mosaic |
bool
|
Whether to apply mosaic at all (regardless of prob). |
True
|
border_value |
Value for filling borders after applying transforms. |
114
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
DetectionNormalize
Bases: DetectionTransform
Normalize image by subtracting mean and dividing by std.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 |
|
DetectionPadToSize
Bases: DetectionTransform
Preprocessing transform to pad image and bboxes to input_dim
shape (rows, cols).
Transform does center padding, so that input image with bboxes located in the center of the produced image.
Note: This transformation assume that dimensions of input image is equal or less than output_size
.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
|
__init__(output_size, pad_value)
Constructor for DetectionPadToSize transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_size |
Union[int, Tuple[int, int], None]
|
Output image size (rows, cols) |
required |
pad_value |
int
|
Padding value for image |
required |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
748 749 750 751 752 753 754 755 756 757 |
|
DetectionPaddedRescale
Bases: DetectionTransform
Preprocessing transform to be applied last of all transforms for validation.
Image- Rescales and pads to self.input_dim. Targets- pads targets to max_targets, moves the class label to first index, converts boxes format- xyxy -> cxcywh.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
Union[int, Tuple[int, int], None]
|
Final input dimension (default=(640,640)) |
required |
swap |
Tuple[int, ...]
|
Image axis's to be rearranged. |
(2, 0, 1)
|
max_targets |
int
|
50
|
|
pad_value |
int
|
Padding value for image. |
114
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 |
|
DetectionRGB2BGR
Bases: DetectionTransform
Detection change Red & Blue channel of the image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prob |
float
|
Probability to apply the transform. |
0.5
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 |
|
DetectionRandomAffine
Bases: DetectionTransform
DetectionRandomAffine detection transform
:param degrees: Degrees for random rotation, when float the random values are drawn uniformly from (-degrees, degrees) :param translate: Translate size (in pixels) for random translation, when float the random values are drawn uniformly from (center-translate, center+translate) :param scales: Values for random rescale, when float the random values are drawn uniformly from (1-scales, 1+scales) :param shear: Degrees for random shear, when float the random values are drawn uniformly from (-shear, shear) :param target_size: Desired output shape. :param filter_box_candidates: Whether to filter out transformed bboxes by edge size, area ratio, and aspect ratio (default=False). :param wh_thr: Edge size threshold when filter_box_candidates = True. Bounding oxes with edges smaller than this values will be filtered out. :param ar_thr: Aspect ratio threshold filter_box_candidates = True. Bounding boxes with aspect ratio larger than this values will be filtered out. :param area_thr: Threshold for area ratio between original image and the transformed one, when filter_box_candidates = True. Bounding boxes with such ratio smaller than this value will be filtered out. :param border_value: Value for filling borders after applying transforms.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
|
DetectionRandomRotate90
Bases: DetectionTransform
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 |
|
xyxy_bbox_rot90(bboxes, factor, rows, cols)
classmethod
Rotates a bounding box by 90 degrees CCW (see np.rot90)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bboxes |
np.ndarray
|
Tensor made of bounding box tuples (x_min, y_min, x_max, y_max). |
required |
factor |
int
|
Number of CCW rotations. Must be in set {0, 1, 2, 3} See np.rot90. |
required |
rows |
int
|
Image rows. |
required |
cols |
int
|
Image cols. |
required |
Returns:
Type | Description |
---|---|
A bounding box tuple (x_min, y_min, x_max, y_max). |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 |
|
DetectionRescale
Bases: DetectionTransform
Resize image and bounding boxes to given image dimensions without preserving aspect ratio
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_shape |
Union[int, Tuple[int, int]]
|
(rows, cols) |
required |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
|
DetectionStandardize
Bases: DetectionTransform
Standardize image pixel values with img/max_val
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_val |
Current maximum value of the image pixels. (usually 255) |
required |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
DetectionTargetsFormatTransform
Bases: DetectionTransform
Detection targets format transform
Convert targets in input_format to output_format, filter small bboxes and pad targets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
Union[int, Tuple[int, int], None]
|
Shape of the images to transform. |
None
|
input_format |
ConcatenatedTensorFormat
|
Format of the input targets. For instance [xmin, ymin, xmax, ymax, cls_id] refers to XYXY_LABEL. |
XYXY_LABEL
|
output_format |
ConcatenatedTensorFormat
|
Format of the output targets. For instance [xmin, ymin, xmax, ymax, cls_id] refers to XYXY_LABEL |
LABEL_CXCYWH
|
min_bbox_edge_size |
float
|
bboxes with edge size lower then this values will be removed. |
1
|
max_targets |
int
|
Max objects in single image, padding target to this size. |
120
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 |
|
apply_on_targets(targets)
Convert targets in input_format to output_format, filter small bboxes and pad targets
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1065 1066 1067 1068 1069 1070 |
|
filter_small_bboxes(targets)
Filter bboxes smaller than specified threshold.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1072 1073 1074 1075 1076 1077 1078 1079 |
|
pad_targets(targets)
Pad targets.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1081 1082 1083 1084 1085 1086 |
|
DetectionTransform
Detection transform base class.
Complex transforms that require extra data loading can use the the additional_samples_count attribute in a similar fashion to what's been done in COCODetectionDataset:
self._load_additional_inputs_for_transform(sample, transform)
after the above call, sample["additional_samples"] holds a list of additional inputs and targets.
sample = transform(sample)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
additional_samples_count |
int
|
Additional samples to be loaded. |
0
|
non_empty_targets |
bool
|
Whether the additional targets can have empty targets or not. |
False
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
SegCropImageAndMask
Bases: SegmentationTransform
Crops image and mask (synchronously). In "center" mode a center crop is performed while, in "random" mode the drop will be positioned around random coordinates.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 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 |
|
__init__(crop_size, mode)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
crop_size |
Union[float, Tuple, List]
|
tuple of (width, height) for the final crop size, if is scalar size is a square (crop_size, crop_size) |
required |
mode |
str
|
how to choose the center of the crop, 'center' for the center of the input image, 'random' center the point is chosen randomally |
required |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
SegPadShortToCropSize
Bases: SegmentationTransform
Pads image to 'crop_size'. Should be called only after "SegRescale" or "SegRandomRescale" in augmentations pipeline.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
294 295 296 297 298 299 300 301 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 332 333 334 335 336 337 338 339 340 |
|
__init__(crop_size, fill_mask=0, fill_image=0)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
crop_size |
Union[float, Tuple, List]
|
Tuple of (width, height) for the final crop size, if is scalar size is a square (crop_size, crop_size) |
required |
fill_mask |
int
|
Value to fill mask labels background. |
0
|
fill_image |
Union[int, Tuple, List]
|
Grey value to fill image padded background. |
0
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
301 302 303 304 305 306 307 308 309 310 311 312 |
|
SegRandomFlip
Bases: SegmentationTransform
Randomly flips the image and mask (synchronously) with probability 'prob'.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
SegRandomGaussianBlur
Bases: SegmentationTransform
Adds random Gaussian Blur to image with probability 'prob'.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
SegRandomRescale
Random rescale the image and mask (synchronously) while preserving aspect ratio. Scale factor is randomly picked between scales [min, max]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scales |
Union[float, Tuple, List]
|
Scale range tuple (min, max), if scales is a float range will be defined as (1, scales) if scales > 1, otherwise (scales, 1). must be a positive number. |
(0.5, 2.0)
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
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 173 174 175 176 177 178 179 180 181 182 183 184 |
|
check_valid_arguments()
Check the scale values are valid. if order is wrong, flip the order and return the right scale values.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
SegRandomRotate
Bases: SegmentationTransform
Randomly rotates image and mask (synchronously) between 'min_deg' and 'max_deg'.
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
SegRescale
Bases: SegmentationTransform
Rescales the image and mask (synchronously) while preserving aspect ratio. The rescaling can be done according to scale_factor, short_size or long_size. If more than one argument is given, the rescaling mode is determined by this order: scale_factor, then short_size, then long_size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale_factor |
Optional[float]
|
Rescaling is done by multiplying input size by scale_factor: out_size = (scale_factor * w, scale_factor * h) |
None
|
short_size |
Optional[int]
|
Rescaling is done by determining the scale factor by the ratio short_size / min(h, w). |
None
|
long_size |
Optional[int]
|
Rescaling is done by determining the scale factor by the ratio long_size / max(h, w). |
None
|
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
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 |
|
Standardize
Bases: torch.nn.Module
Standardize image pixel values.
Returns:
Type | Description |
---|---|
max_val: float, value to as described above (default=255) |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 |
|
get_affine_matrix(input_size, target_size, degrees=10, translate=0.1, scales=0.1, shear=10)
Return a random affine transform matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_size |
Tuple[int, int]
|
Input shape. |
required |
target_size |
Tuple[int, int]
|
Desired output shape. |
required |
degrees |
Union[tuple, float]
|
Degrees for random rotation, when float the random values are drawn uniformly from (-degrees, degrees) |
10
|
translate |
Union[tuple, float]
|
Translate size (in pixels) for random translation, when float the random values are drawn uniformly from (-translate, translate) |
0.1
|
scales |
Union[tuple, float]
|
Values for random rescale, when float the random values are drawn uniformly from (1-scales, 1+scales) |
0.1
|
shear |
Union[tuple, float]
|
Degrees for random shear, when float the random values are drawn uniformly from (-shear, shear) |
10
|
Returns:
Type | Description |
---|---|
np.ndarray
|
affine_transform_matrix, drawn_scale |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
|
get_aug_params(value, center=0)
Generates a random value for augmentations as described below
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Union[tuple, float]
|
Range of values for generation. Wen tuple-drawn uniformly between (value[0], value[1]), and (center - value, center + value) when float. |
required |
center |
float
|
Center to subtract when value is float. |
0
|
Returns:
Type | Description |
---|---|
float
|
Generated value |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 |
|
random_affine(img, targets=(), targets_seg=None, target_size=(640, 640), degrees=10, translate=0.1, scales=0.1, shear=10, filter_box_candidates=False, wh_thr=2, ar_thr=20, area_thr=0.1, border_value=114)
Performs random affine transform to img, targets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
np.ndarray
|
Input image of shape [h, w, c] |
required |
targets |
np.ndarray
|
Input target |
()
|
targets_seg |
np.ndarray
|
Targets derived from segmentation masks |
None
|
target_size |
tuple
|
Desired output shape |
(640, 640)
|
degrees |
Union[float, tuple]
|
Degrees for random rotation, when float the random values are drawn uniformly from (-degrees, degrees). |
10
|
translate |
Union[float, tuple]
|
Translate size (in pixels) for random translation, when float the random values are drawn uniformly from (-translate, translate) |
0.1
|
scales |
Union[float, tuple]
|
Values for random rescale, when float the random values are drawn uniformly from (0.1-scales, 0.1+scales) |
0.1
|
shear |
Union[float, tuple]
|
Degrees for random shear, when float the random values are drawn uniformly from (shear, shear) |
10
|
filter_box_candidates |
bool
|
whether to filter out transformed bboxes by edge size, area ratio, and aspect ratio. |
False
|
wh_thr |
(float) edge size threshold when filter_box_candidates = True. Bounding oxes with edges smaller then this values will be filtered out. (default=2) |
2
|
|
ar_thr |
(float) aspect ratio threshold filter_box_candidates = True. Bounding boxes with aspect ratio larger then this values will be filtered out. (default=20) |
20
|
|
area_thr |
(float) threshold for area ratio between original image and the transformed one, when when filter_box_candidates = True. Bounding boxes with such ratio smaller then this value will be filtered out. (default=0.1) |
0.1
|
|
border_value |
value for filling borders after applying transforms (default=114). |
114
|
Returns:
Type | Description |
---|---|
Image and Target with applied random affine |
Source code in V3_1/src/super_gradients/training/transforms/transforms.py
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 |
|