Processing
AutoPadding
Bases: Processing
, ABC
Source code in latest/src/super_gradients/training/processing/processing.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
__init__(shape_multiple, pad_value)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape_multiple |
Tuple[int, int]
|
Tuple of (H, W) indicating the height and width multiples to which the input image dimensions will be padded. For instance, with a value of (32, 40), an input image of size (45, 67) will be padded to (64, 80). |
required |
pad_value |
int
|
Value to pad the image with. |
required |
Source code in latest/src/super_gradients/training/processing/processing.py
114 115 116 117 118 119 120 121 |
|
CenterCrop
Bases: ClassificationProcess
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
Desired output size of the crop. |
224
|
Source code in latest/src/super_gradients/training/processing/processing.py
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 |
|
infer_image_input_shape()
Infer the output image shape from the processing.
Returns:
Type | Description |
---|---|
Optional[Tuple[int, int]]
|
(rows, cols) Returns the last known output shape for all the processings. |
Source code in latest/src/super_gradients/training/processing/processing.py
675 676 677 678 679 680 681 |
|
preprocess_image(image)
Crops the given image at the center.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
Image, in (H, W, C) format. |
required |
Returns:
Type | Description |
---|---|
Tuple[np.ndarray, None]
|
The center cropped image. |
Source code in latest/src/super_gradients/training/processing/processing.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
|
ComposeProcessing
Bases: Processing
Compose a list of Processing objects into a single Processing object.
Source code in latest/src/super_gradients/training/processing/processing.py
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
__init__(processings)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
processings |
List[Processing]
|
List of Processing objects to compose. |
required |
Source code in latest/src/super_gradients/training/processing/processing.py
136 137 138 139 140 |
|
get_equivalent_compose_without_resizing(auto_padding)
Get a composed processing equivalent to this one, but without resizing the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto_padding |
AutoPadding
|
AutoPadding object to use for padding the image. This is required since models often expect input image to be a multiple of a specific shape (usually 32x32). This padding operation will be applied on the input image before any other processing. |
required |
Returns:
Type | Description |
---|---|
ComposeProcessing
|
A composed processing equivalent to this one, but without resizing the image. |
Source code in latest/src/super_gradients/training/processing/processing.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
infer_image_input_shape()
Infer the output image shape from the processing.
Returns:
Type | Description |
---|---|
Optional[Tuple[int, int]]
|
(rows, cols) Returns the last known output shape for all the processings. |
Source code in latest/src/super_gradients/training/processing/processing.py
166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
postprocess_predictions(predictions, metadata)
Postprocess the model output predictions.
Source code in latest/src/super_gradients/training/processing/processing.py
150 151 152 153 154 155 |
|
preprocess_image(image)
Processing an image, before feeding it to the network.
Source code in latest/src/super_gradients/training/processing/processing.py
142 143 144 145 146 147 148 |
|
ImagePermute
Bases: Processing
Permute the image dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
permutation |
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 latest/src/super_gradients/training/processing/processing.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
NormalizeImage
Bases: Processing
Normalize an image based on means and standard deviation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean |
List[float]
|
Mean values for each channel. |
required |
std |
List[float]
|
Standard deviation values for each channel. |
required |
Source code in latest/src/super_gradients/training/processing/processing.py
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 |
|
Processing
Bases: ABC
Interface for preprocessing and postprocessing methods that are used to prepare images for a model and process the model's output.
Subclasses should implement the preprocess_image
and postprocess_predictions
methods according to the specific requirements of the model and task.
Source code in latest/src/super_gradients/training/processing/processing.py
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 |
|
resizes_image: bool
abstractmethod
property
Return True if the processing resizes the image, False otherwise.
get_equivalent_photometric_module()
abstractmethod
Get the equivalent photometric preprocessing module for this processing. A photometric preprocessing apply a transformation to the image pixels, without changing the image size. This includes RGB -> BGR, standardization, normalization etc. If a Processing subclass does not have change pixel values, it should return an nn.Identity module. If a Processing subclass does not have an equivalent photometric preprocessing, it should return None.
Returns:
Type | Description |
---|---|
Optional[nn.Module]
|
Source code in latest/src/super_gradients/training/processing/processing.py
85 86 87 88 89 90 91 92 93 94 95 |
|
infer_image_input_shape()
Infer the shape (rows, cols) of the image after all the processing steps. This is the effective image size that is fed to model itself
Returns:
Type | Description |
---|---|
Optional[Tuple[int, int]]
|
Return the image shape (rows, cols), or None if the image shape cannot be inferred (When preprocessing contains no resize/padding operations). |
Source code in latest/src/super_gradients/training/processing/processing.py
97 98 99 100 101 102 103 104 |
|
postprocess_predictions(predictions, metadata)
abstractmethod
Postprocess the model output predictions.
Source code in latest/src/super_gradients/training/processing/processing.py
80 81 82 83 |
|
preprocess_image(image)
abstractmethod
Processing an image, before feeding it to the network. Expected to be in (H, W, C) or (H, W).
Source code in latest/src/super_gradients/training/processing/processing.py
75 76 77 78 |
|
ProcessingMetadata
dataclass
Bases: ABC
Metadata including information to postprocess a prediction.
Source code in latest/src/super_gradients/training/processing/processing.py
33 34 35 |
|
Resize
Bases: ClassificationProcess
Source code in latest/src/super_gradients/training/processing/processing.py
612 613 614 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 |
|
preprocess_image(image)
Resize an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
Image, in (H, W, C) format. |
required |
Returns:
Type | Description |
---|---|
Tuple[np.ndarray, None]
|
The resized image. |
Source code in latest/src/super_gradients/training/processing/processing.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
|
ReverseImageChannels
Bases: Processing
Reverse the order of the image channels (RGB -> BGR or BGR -> RGB).
Source code in latest/src/super_gradients/training/processing/processing.py
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 |
|
preprocess_image(image)
Reverse the channel order of an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
Image, in (H, W, C) format. |
required |
Returns:
Type | Description |
---|---|
Tuple[np.ndarray, None]
|
Image with reversed channel order. (RGB if input was BGR, BGR if input was RGB) |
Source code in latest/src/super_gradients/training/processing/processing.py
232 233 234 235 236 237 238 239 240 241 242 243 |
|
SegmentationPadShortToCropSize
Bases: Processing
Pads image to 'crop_size'.
Should be called only after "SegRescale" or "SegRandomRescale" in augmentations pipeline.
:param crop_size: Tuple of (width, height) for the final crop size, if is scalar size is a square (crop_size, crop_size)
= :param fill_image: Grey value to fill image padded background.
Source code in latest/src/super_gradients/training/processing/processing.py
809 810 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 836 837 838 839 840 841 842 843 |
|
SegmentationPadToDivisible
Bases: Processing
Pads image to a size divisible by the defined parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisible_value |
int
|
The divisible value, new image size is an int multiplication of this number |
required |
fill_image |
Union[int, Tuple, List]
|
The value to use for padding the image. |
required |
Source code in latest/src/super_gradients/training/processing/processing.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
|
SegmentationRescale
Bases: Processing
Rescale image by scaling factor 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 latest/src/super_gradients/training/processing/processing.py
734 735 736 737 738 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 771 772 773 774 775 |
|
resizes_image: bool
property
Return True if the processing resizes the image, False otherwise.
SegmentationResize
Bases: Processing
Resize image to given image dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_shape |
Tuple[int, int]
|
output shape will be (output_h, output_w) |
required |
Source code in latest/src/super_gradients/training/processing/processing.py
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 |
|
SegmentationResizeWithPadding
Bases: Processing
Resize image to given image dimensions while preserving aspect ratio (padding might be used).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_shape |
Tuple[int, int]
|
(H, W) |
required |
pad_value |
int
|
padding value (will be used if padding needed) |
required |
Source code in latest/src/super_gradients/training/processing/processing.py
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 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
|
StandardizeImage
Bases: Processing
Standardize image pixel values with img/max_val
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_value |
float
|
Current maximum value of the image pixels. (usually 255) |
255.0
|
Source code in latest/src/super_gradients/training/processing/processing.py
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 |
|
preprocess_image(image)
Reverse the channel order of an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
Image, in (H, W, C) format. |
required |
Returns:
Type | Description |
---|---|
Tuple[np.ndarray, None]
|
Image with reversed channel order. (RGB if input was BGR, BGR if input was RGB) |
Source code in latest/src/super_gradients/training/processing/processing.py
269 270 271 272 273 274 275 276 |
|
default_cityscapes_processing_params(scale=1)
Processing parameters commonly used for training segmentation models on Cityscapes dataset.
Source code in latest/src/super_gradients/training/processing/processing.py
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 |
|
default_dekr_coco_processing_params()
Processing parameters commonly used for training DEKR on COCO dataset.
Source code in latest/src/super_gradients/training/processing/processing.py
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 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 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 |
|
default_imagenet_processing_params()
Processing parameters commonly used for training resnet on Imagenet dataset.
Source code in latest/src/super_gradients/training/processing/processing.py
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 |
|
default_ppyoloe_coco_processing_params()
Processing parameters commonly used for training PPYoloE on COCO dataset. TODO: remove once we load it from the checkpoint
Source code in latest/src/super_gradients/training/processing/processing.py
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 |
|
default_segformer_cityscapes_processing_params()
Processing parameters commonly used for training Segformer on Cityscapes dataset.
Source code in latest/src/super_gradients/training/processing/processing.py
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
|
default_vit_imagenet_processing_params()
Processing parameters used by ViT for training resnet on Imagenet dataset.
Source code in latest/src/super_gradients/training/processing/processing.py
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 |
|
default_yolo_nas_coco_processing_params()
Processing parameters commonly used for training YoloNAS on COCO dataset. TODO: remove once we load it from the checkpoint
Source code in latest/src/super_gradients/training/processing/processing.py
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 |
|
default_yolox_coco_processing_params()
Processing parameters commonly used for training YoloX on COCO dataset. TODO: remove once we load it from the checkpoint
Source code in latest/src/super_gradients/training/processing/processing.py
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
|
get_pretrained_processing_params(model_name, pretrained_weights)
Get the processing parameters for a pretrained model. TODO: remove once we load it from the checkpoint
Source code in latest/src/super_gradients/training/processing/processing.py
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
|