Skip to content

Commit 1135a1f

Browse files
authored
docs: fixed warnings and improved formatting (#207)
1 parent 4240f17 commit 1135a1f

File tree

13 files changed

+243
-221
lines changed

13 files changed

+243
-221
lines changed

luxonis_ml/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pkg_resources
22

3-
from ..guard_extras import guard_missing_extra
3+
from luxonis_ml.guard_extras import guard_missing_extra
44

55
with guard_missing_extra("data"):
66
from .augmentations import Augmentations

luxonis_ml/data/augmentations/batch_compose.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def __init__(
4242
4343
@param transforms: List of transformations to compose
4444
@type transforms: TransformsSeqType
45-
@param bboxparams: Parameters for bounding boxes transforms. Defaults to None.
46-
@type bboxparams: Optional[Union[dict, BboxParams]]
45+
@param bbox_params: Parameters for bounding boxes transforms. Defaults to None.
46+
@type bbox_params: Optional[Union[dict, BboxParams]]
4747
@param keypoint_params: Parameters for keypoint transforms. Defaults to None.
4848
@type keypoint_params: Optional[Union[dict, KeypointParams]]
4949
@param additional_targets: Dict with keys - new target name, values - old target
@@ -283,8 +283,8 @@ def __init__(
283283
284284
@param transforms: List of transformations to compose
285285
@type transforms: TransformsSeqType
286-
@param bboxparams: Parameters for bounding boxes transforms. Defaults to None.
287-
@type bboxparams: Optional[Union[dict, BboxParams]]
286+
@param bbox_params: Parameters for bounding boxes transforms. Defaults to None.
287+
@type bbox_params: Optional[Union[dict, BboxParams]]
288288
@param keypoint_params: Parameters for keypoint transforms. Defaults to None.
289289
@type keypoint_params: Optional[Union[dict, KeypointParams]]
290290
@param additional_targets: Dict with keys - new target name, values - old target

luxonis_ml/data/augmentations/custom/letterbox_resize.py

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ def __init__(
2323
"""Augmentation to apply letterbox resizing to images. Also
2424
transforms masks, bboxes and keypoints to correct shape.
2525
26-
@param height: Desired height of the output.
2726
@type height: int
28-
@param width: Desired width of the output.
27+
@param height: Desired height of the output.
2928
@type width: int
30-
@param interpolation: Cv2 flag to specify interpolation used
31-
when resizing. Defaults to cv2.INTER_LINEAR.
29+
@param width: Desired width of the output.
3230
@type interpolation: int, optional
33-
@param border_value: Padding value for images. Defaults to 0.
31+
@param interpolation: cv2 flag to specify interpolation used
32+
when resizing. Defaults to C{cv2.INTER_LINEAR}.
3433
@type border_value: int, optional
35-
@param mask_value: Padding value for masks. Defaults to 0.
34+
@param border_value: Padding value for images. Defaults to C{0}.
3635
@type mask_value: int, optional
37-
@param always_apply: Whether to always apply the transform.
38-
Defaults to False.
36+
@param mask_value: Padding value for masks. Defaults to C{0}.
3937
@type always_apply: bool, optional
40-
@param p: Probability of applying the transform. Defaults to
41-
1.0.
38+
@param always_apply: Whether to always apply the transform.
39+
Defaults to C{False}.
4240
@type p: float, optional
41+
@param p: Probability of applying the transform. Defaults to
42+
C{1.0}.
4343
"""
4444

4545
super().__init__(always_apply, p)
@@ -108,20 +108,20 @@ def apply(
108108
) -> np.ndarray:
109109
"""Applies the letterbox augmentation to an image.
110110
111-
@param img: Input image to which resize is applied.
112111
@type img: np.ndarray
113-
@param pad_top: Number of pixels to pad at the top.
112+
@param img: Input image to which resize is applied.
114113
@type pad_top: int
115-
@param pad_bottom: Number of pixels to pad at the bottom.
114+
@param pad_top: Number of pixels to pad at the top.
116115
@type pad_bottom: int
117-
@param pad_left: Number of pixels to pad on the left.
116+
@param pad_bottom: Number of pixels to pad at the bottom.
118117
@type pad_left: int
119-
@param pad_right: Number of pixels to pad on the right.
118+
@param pad_left: Number of pixels to pad on the left.
120119
@type pad_right: int
121-
@param params: Additional parameters for the padding operation.
122-
@type params: Any
123-
@return: Image with applied letterbox resize.
120+
@param pad_right: Number of pixels to pad on the right.
121+
@type kwargs: Any
122+
@param kwargs: Additional parameters for the padding operation.
124123
@rtype: np.ndarray
124+
@return: Image with applied letterbox resize.
125125
"""
126126

127127
resized_img = cv2.resize(
@@ -155,20 +155,20 @@ def apply_to_mask(
155155
) -> np.ndarray:
156156
"""Applies letterbox augmentation to the input mask.
157157
158-
@param img: Input mask to which resize is applied.
159158
@type img: np.ndarray
160-
@param pad_top: Number of pixels to pad at the top.
159+
@param img: Input mask to which resize is applied.
161160
@type pad_top: int
162-
@param pad_bottom: Number of pixels to pad at the bottom.
161+
@param pad_top: Number of pixels to pad at the top.
163162
@type pad_bottom: int
164-
@param pad_left: Number of pixels to pad on the left.
163+
@param pad_bottom: Number of pixels to pad at the bottom.
165164
@type pad_left: int
166-
@param pad_right: Number of pixels to pad on the right.
165+
@param pad_left: Number of pixels to pad on the left.
167166
@type pad_right: int
168-
@param params: Additional parameters for the padding operation.
167+
@param pad_right: Number of pixels to pad on the right.
169168
@type params: Any
170-
@return: Mask with applied letterbox resize.
169+
@param params: Additional parameters for the padding operation.
171170
@rtype: np.ndarray
171+
@return: Mask with applied letterbox resize.
172172
"""
173173

174174
resized_img = cv2.resize(
@@ -202,20 +202,20 @@ def apply_to_bbox(
202202
) -> BoxType:
203203
"""Applies letterbox augmentation to the bounding box.
204204
205-
@param img: Bounding box to which resize is applied.
206-
@type img: BoxType
207-
@param pad_top: Number of pixels to pad at the top.
205+
@type bbox: BoxType
206+
@param bbox: Bounding box to which resize is applied.
208207
@type pad_top: int
209-
@param pad_bottom: Number of pixels to pad at the bottom.
208+
@param pad_top: Number of pixels to pad at the top.
210209
@type pad_bottom: int
211-
@param pad_left: Number of pixels to pad on the left.
210+
@param pad_bottom: Number of pixels to pad at the bottom.
212211
@type pad_left: int
213-
@param pad_right: Number of pixels to pad on the right.
212+
@param pad_left: Number of pixels to pad on the left.
214213
@type pad_right: int
215-
@param params: Additional parameters for the padding operation.
214+
@param pad_right: Number of pixels to pad on the right.
216215
@type params: Any
217-
@return: Bounding box with applied letterbox resize.
216+
@param params: Additional parameters for the padding operation.
218217
@rtype: BoxType
218+
@return: Bounding box with applied letterbox resize.
219219
"""
220220

221221
x_min, y_min, x_max, y_max = denormalize_bbox(
@@ -245,29 +245,29 @@ def apply_to_keypoint(
245245
pad_bottom: int,
246246
pad_left: int,
247247
pad_right: int,
248-
**params,
248+
**kwargs,
249249
) -> KeypointType:
250250
"""Applies letterbox augmentation to the keypoint.
251251
252-
@param img: Keypoint to which resize is applied.
253-
@type img: KeypointType
254-
@param pad_top: Number of pixels to pad at the top.
252+
@type keypoint: KeypointType
253+
@param keypoint: Keypoint to which resize is applied.
255254
@type pad_top: int
256-
@param pad_bottom: Number of pixels to pad at the bottom.
255+
@param pad_top: Number of pixels to pad at the top.
257256
@type pad_bottom: int
258-
@param pad_left: Number of pixels to pad on the left.
257+
@param pad_bottom: Number of pixels to pad at the bottom.
259258
@type pad_left: int
260-
@param pad_right: Number of pixels to pad on the right.
259+
@param pad_left: Number of pixels to pad on the left.
261260
@type pad_right: int
262-
@param params: Additional parameters for the padding operation.
263-
@type params: Any
264-
@return: Keypoint with applied letterbox resize.
261+
@param pad_right: Number of pixels to pad on the right.
262+
@type kwargs: Any
263+
@param kwargs: Additional parameters for the padding operation.
265264
@rtype: KeypointType
265+
@return: Keypoint with applied letterbox resize.
266266
"""
267267

268268
x, y, angle, scale = keypoint[:4]
269-
scale_x = (self.width - pad_left - pad_right) / params["cols"]
270-
scale_y = (self.height - pad_top - pad_bottom) / params["rows"]
269+
scale_x = (self.width - pad_left - pad_right) / kwargs["cols"]
270+
scale_y = (self.height - pad_top - pad_bottom) / kwargs["rows"]
271271
new_x = (x * scale_x) + pad_left
272272
new_y = (y * scale_y) + pad_top
273273
# if keypoint is in the padding then set coordinates to -1
@@ -286,8 +286,8 @@ def apply_to_keypoint(
286286
def get_transform_init_args_names(self) -> Tuple[str, ...]:
287287
"""Gets the default arguments for the letterbox augmentation.
288288
289-
@return: The string keywords of the arguments.
290289
@rtype: Tuple[str, ...]
290+
@return: The string keywords of the arguments.
291291
"""
292292

293293
return (
@@ -303,14 +303,14 @@ def _out_of_bounds(
303303
) -> bool:
304304
""" "Check if the given value is outside the specified limits.
305305
306-
@param value: The value to be checked.
307306
@type value: float
308-
@param min_limit: Minimum limit.
307+
@param value: The value to be checked.
309308
@type min_limit: float
310-
@param max_limit: Maximum limit.
309+
@param min_limit: Minimum limit.
311310
@type max_limit: float
311+
@param max_limit: Maximum limit.
312+
@rtype: bool
312313
@return: True if the value is outside the specified limits,
313314
False otherwise.
314-
@rtype: bool
315315
"""
316316
return value < min_limit or value > max_limit

luxonis_ml/data/augmentations/custom/mixup.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ def __init__(
2323
annotations into one. If images are not of same size then second
2424
one is first resized to match the first one.
2525
26+
@type alpha: Union[float, Tuple[float, float]]
2627
@param alpha: Mixing coefficient, either a single float or a
27-
tuple representing the range. Defaults to 0.5.
28-
@type alpha: Union[float, Tuple[float, float]], optional
28+
tuple representing the range. Defaults to C{0.5}.
29+
@type out_batch_size: int
2930
@param out_batch_size: Number of output images in the batch.
30-
Defaults to 1.
31-
@type out_batch_size: int, optional
31+
Defaults to C{1}.
32+
@type always_apply: bool
3233
@param always_apply: Whether to always apply the transform.
33-
Defaults to False.
34-
@type always_apply: bool, optional
35-
@param p: Probability of applying the transform. Defaults to
36-
0.5.
34+
Defaults to C{False}.
3735
@type p: float, optional
36+
@param p: Probability of applying the transform. Defaults to
37+
C{0.5}.
3838
"""
3939
super().__init__(batch_size=2, always_apply=always_apply, p=p)
4040

@@ -44,17 +44,17 @@ def __init__(
4444
def get_transform_init_args_names(self) -> Tuple[str, ...]:
4545
"""Gets the default arguments for the mixup augmentation.
4646
47-
@return: The string keywords of the arguments.
4847
@rtype: Tuple[str, ...]
48+
@return: The string keywords of the arguments.
4949
"""
5050
return ("alpha", "out_batch_size")
5151

5252
@property
5353
def targets_as_params(self) -> List[str]:
5454
"""List of augmentation targets.
5555
56-
@return: Output list of augmentation targets.
5756
@rtype: List[str]
57+
@return: Output list of augmentation targets.
5858
"""
5959
return ["image_batch"]
6060

@@ -66,15 +66,15 @@ def apply_to_image_batch(
6666
) -> List[np.ndarray]:
6767
"""Applies the transformation to a batch of images.
6868
69+
@type image_batch: List[np.ndarray]
6970
@param image_batch: Batch of input images to which the
7071
transformation is applied.
71-
@type image_batch: List[np.ndarray]
72-
@param image_shapes: Shapes of the input images in the batch.
7372
@type image_shapes: List[Tuple[int, int]]
74-
@param params: Additional parameters for the transformation.
73+
@param image_shapes: Shapes of the input images in the batch.
7574
@type params: Any
76-
@return: List of transformed images.
75+
@param params: Additional parameters for the transformation.
7776
@rtype: List[np.ndarray]
77+
@return: List of transformed images.
7878
"""
7979
image1 = image_batch[0]
8080
# resize second image to size of the first one
@@ -101,15 +101,15 @@ def apply_to_mask_batch(
101101
) -> List[np.ndarray]:
102102
"""Applies the transformation to a batch of masks.
103103
104-
@param image_batch: Batch of input masks to which the
104+
@type mask_batch: List[np.ndarray]
105+
@param mask_batch: Batch of input masks to which the
105106
transformation is applied.
106-
@type image_batch: List[np.ndarray]
107-
@param image_shapes: Shapes of the input images in the batch.
108107
@type image_shapes: List[Tuple[int, int]]
109-
@param params: Additional parameters for the transformation.
108+
@param image_shapes: Shapes of the input images in the batch.
110109
@type params: Any
111-
@return: List of transformed masks.
110+
@param params: Additional parameters for the transformation.
112111
@rtype: List[np.ndarray]
112+
@return: List of transformed masks.
113113
"""
114114
mask1 = mask_batch[0]
115115
mask2 = cv2.resize(
@@ -127,39 +127,39 @@ def apply_to_bboxes_batch(
127127
self,
128128
bboxes_batch: List[BoxType],
129129
image_shapes: List[Tuple[int, int]],
130-
**params,
130+
**kwargs,
131131
) -> List[BoxType]:
132132
"""Applies the transformation to a batch of bboxes.
133133
134-
@param image_batch: Batch of input bboxes to which the
134+
@type bboxes_batch: List[BoxType]
135+
@param bboxes_batch: Batch of input bboxes to which the
135136
transformation is applied.
136-
@type image_batch: List[BoxType]
137-
@param image_shapes: Shapes of the input images in the batch.
138137
@type image_shapes: List[Tuple[int, int]]
139-
@param params: Additional parameters for the transformation.
140-
@type params: Any
141-
@return: List of transformed bboxes.
138+
@param image_shapes: Shapes of the input images in the batch.
139+
@type kwargs: Any
140+
@param kwargs: Additional parameters for the transformation.
142141
@rtype: List[BoxType]
142+
@return: List of transformed bboxes.
143143
"""
144144
return [bboxes_batch[0] + bboxes_batch[1]]
145145

146146
def apply_to_keypoints_batch(
147147
self,
148148
keypoints_batch: List[KeypointType],
149149
image_shapes: List[Tuple[int, int]],
150-
**params,
150+
**kwargs,
151151
) -> List[KeypointType]:
152152
"""Applies the transformation to a batch of keypoints.
153153
154-
@param image_batch: Batch of input keypoints to which the
154+
@type keypoints_batch: List[BoxType]
155+
@param keypoints_batch: Batch of input keypoints to which the
155156
transformation is applied.
156-
@type image_batch: List[BoxType]
157-
@param image_shapes: Shapes of the input images in the batch.
158157
@type image_shapes: List[Tuple[int, int]]
159-
@param params: Additional parameters for the transformation.
160-
@type params: Any
161-
@return: List of transformed keypoints.
158+
@param image_shapes: Shapes of the input images in the batch.
159+
@type kwargs: Any
160+
@param kwargs: Additional parameters for the transformation.
162161
@rtype: List[BoxType]
162+
@return: List of transformed keypoints.
163163
"""
164164
scaled_kpts2 = []
165165
scale_x = image_shapes[0][1] / image_shapes[1][1]

0 commit comments

Comments
 (0)