unitorch.cli.models¤
Image¤
Processor for image-related operations.
Source code in src/unitorch/cli/models/image_utils.py
25 26 27 28 29 30 31 32 33 | |
from_config
classmethod
¤
from_config(config, **kwargs)
Source code in src/unitorch/cli/models/image_utils.py
35 36 37 38 | |
_request_url ¤
_request_url(url)
Retry-loop GET request returning the response.
Source code in src/unitorch/cli/models/image_utils.py
40 41 42 43 44 45 46 47 | |
_read ¤
_read(image, image_type=None)
Read an image from a file path, base64/hex string, or HTTP URL.
Source code in src/unitorch/cli/models/image_utils.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
_translate ¤
_translate(
image: Image,
up: Optional[int] = 0,
left: Optional[int] = 0,
)
Translate the image by (left, up) pixels using an affine transform.
Source code in src/unitorch/cli/models/image_utils.py
79 80 81 82 83 84 85 86 87 | |
_scale ¤
_scale(image: Image, scale: Optional[float] = 0.0)
Scale the image by the given factor.
Source code in src/unitorch/cli/models/image_utils.py
89 90 91 92 93 94 95 96 | |
_rotate ¤
_rotate(image: Image, degree: Optional[int] = 0.0)
Rotate the image by the given degree with expansion.
Source code in src/unitorch/cli/models/image_utils.py
98 99 100 101 102 103 104 105 | |
_flip ¤
_flip(
image: Image,
horizontal: Optional[bool] = False,
vertical: Optional[bool] = False,
)
Flip the image horizontally and/or vertically.
Source code in src/unitorch/cli/models/image_utils.py
107 108 109 110 111 112 113 114 115 116 117 118 119 | |
_resize ¤
_resize(
image: Image,
size: Optional[Tuple[int, int]] = (256, 256),
)
Resize the image using Lanczos resampling.
Source code in src/unitorch/cli/models/image_utils.py
121 122 123 124 125 126 127 128 | |
_canny ¤
_canny(image: Image)
Detect edges using Canny (OpenCV if available, otherwise PIL FIND_EDGES).
Source code in src/unitorch/cli/models/image_utils.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
_mask ¤
_mask(image: Image, mask: Image)
Source code in src/unitorch/cli/models/image_utils.py
148 149 150 151 152 153 154 155 156 157 | |
_dilate ¤
_dilate(
image: Image,
kernel_size: Optional[int] = 3,
iterations: Optional[int] = 1,
)
Dilate the image using an ellipse kernel (requires OpenCV).
Source code in src/unitorch/cli/models/image_utils.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
_crop ¤
_crop(image: Image, box: Tuple[int, int, int, int])
Crop the image to the given (left, upper, right, lower) box.
Source code in src/unitorch/cli/models/image_utils.py
179 180 181 182 183 184 185 186 | |
_center_crop ¤
_center_crop(
image: Image,
size: Optional[Tuple[int, int]] = (224, 224),
)
Crop the image to the given size from the center.
Source code in src/unitorch/cli/models/image_utils.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
Labels¤
Processor for label-related operations.
Source code in src/unitorch/cli/models/label_utils.py
18 19 20 21 22 23 24 25 26 27 28 | |
from_config
classmethod
¤
from_config(config, **kwargs)
Source code in src/unitorch/cli/models/label_utils.py
30 31 32 33 | |
_label ¤
_label(
text: Union[int, float, str],
dtype: Optional[str] = "int",
)
Convert a scalar label to a ClassificationTargets tensor.
Source code in src/unitorch/cli/models/label_utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
_sequence_label ¤
_sequence_label(
text: Union[List, str],
sep: Optional[str] = None,
dtype: Optional[str] = "int",
)
Convert a sequence of labels to a ClassificationTargets tensor.
Source code in src/unitorch/cli/models/label_utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
_binary_label ¤
_binary_label(
text: Union[List, str], sep: Optional[str] = None
)
Build a multi-hot binary ClassificationTargets tensor of length num_classes.
Source code in src/unitorch/cli/models/label_utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |