Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fixed warnings and improved formatting #207

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion luxonis_ml/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pkg_resources

from ..guard_extras import guard_missing_extra
from luxonis_ml.guard_extras import guard_missing_extra

with guard_missing_extra("data"):
from .augmentations import Augmentations
Expand Down
8 changes: 4 additions & 4 deletions luxonis_ml/data/augmentations/batch_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def __init__(

@param transforms: List of transformations to compose
@type transforms: TransformsSeqType
@param bboxparams: Parameters for bounding boxes transforms. Defaults to None.
@type bboxparams: Optional[Union[dict, BboxParams]]
@param bbox_params: Parameters for bounding boxes transforms. Defaults to None.
@type bbox_params: Optional[Union[dict, BboxParams]]
@param keypoint_params: Parameters for keypoint transforms. Defaults to None.
@type keypoint_params: Optional[Union[dict, KeypointParams]]
@param additional_targets: Dict with keys - new target name, values - old target
Expand Down Expand Up @@ -283,8 +283,8 @@ def __init__(

@param transforms: List of transformations to compose
@type transforms: TransformsSeqType
@param bboxparams: Parameters for bounding boxes transforms. Defaults to None.
@type bboxparams: Optional[Union[dict, BboxParams]]
@param bbox_params: Parameters for bounding boxes transforms. Defaults to None.
@type bbox_params: Optional[Union[dict, BboxParams]]
@param keypoint_params: Parameters for keypoint transforms. Defaults to None.
@type keypoint_params: Optional[Union[dict, KeypointParams]]
@param additional_targets: Dict with keys - new target name, values - old target
Expand Down
100 changes: 50 additions & 50 deletions luxonis_ml/data/augmentations/custom/letterbox_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ def __init__(
"""Augmentation to apply letterbox resizing to images. Also
transforms masks, bboxes and keypoints to correct shape.

@param height: Desired height of the output.
@type height: int
@param width: Desired width of the output.
@param height: Desired height of the output.
@type width: int
@param interpolation: Cv2 flag to specify interpolation used
when resizing. Defaults to cv2.INTER_LINEAR.
@param width: Desired width of the output.
@type interpolation: int, optional
@param border_value: Padding value for images. Defaults to 0.
@param interpolation: cv2 flag to specify interpolation used
when resizing. Defaults to C{cv2.INTER_LINEAR}.
@type border_value: int, optional
@param mask_value: Padding value for masks. Defaults to 0.
@param border_value: Padding value for images. Defaults to C{0}.
@type mask_value: int, optional
@param always_apply: Whether to always apply the transform.
Defaults to False.
@param mask_value: Padding value for masks. Defaults to C{0}.
@type always_apply: bool, optional
@param p: Probability of applying the transform. Defaults to
1.0.
@param always_apply: Whether to always apply the transform.
Defaults to C{False}.
@type p: float, optional
@param p: Probability of applying the transform. Defaults to
C{1.0}.
"""

super().__init__(always_apply, p)
Expand Down Expand Up @@ -108,20 +108,20 @@ def apply(
) -> np.ndarray:
"""Applies the letterbox augmentation to an image.

@param img: Input image to which resize is applied.
@type img: np.ndarray
@param pad_top: Number of pixels to pad at the top.
@param img: Input image to which resize is applied.
@type pad_top: int
@param pad_bottom: Number of pixels to pad at the bottom.
@param pad_top: Number of pixels to pad at the top.
@type pad_bottom: int
@param pad_left: Number of pixels to pad on the left.
@param pad_bottom: Number of pixels to pad at the bottom.
@type pad_left: int
@param pad_right: Number of pixels to pad on the right.
@param pad_left: Number of pixels to pad on the left.
@type pad_right: int
@param params: Additional parameters for the padding operation.
@type params: Any
@return: Image with applied letterbox resize.
@param pad_right: Number of pixels to pad on the right.
@type kwargs: Any
@param kwargs: Additional parameters for the padding operation.
@rtype: np.ndarray
@return: Image with applied letterbox resize.
"""

resized_img = cv2.resize(
Expand Down Expand Up @@ -155,20 +155,20 @@ def apply_to_mask(
) -> np.ndarray:
"""Applies letterbox augmentation to the input mask.

@param img: Input mask to which resize is applied.
@type img: np.ndarray
@param pad_top: Number of pixels to pad at the top.
@param img: Input mask to which resize is applied.
@type pad_top: int
@param pad_bottom: Number of pixels to pad at the bottom.
@param pad_top: Number of pixels to pad at the top.
@type pad_bottom: int
@param pad_left: Number of pixels to pad on the left.
@param pad_bottom: Number of pixels to pad at the bottom.
@type pad_left: int
@param pad_right: Number of pixels to pad on the right.
@param pad_left: Number of pixels to pad on the left.
@type pad_right: int
@param params: Additional parameters for the padding operation.
@param pad_right: Number of pixels to pad on the right.
@type params: Any
@return: Mask with applied letterbox resize.
@param params: Additional parameters for the padding operation.
@rtype: np.ndarray
@return: Mask with applied letterbox resize.
"""

resized_img = cv2.resize(
Expand Down Expand Up @@ -202,20 +202,20 @@ def apply_to_bbox(
) -> BoxType:
"""Applies letterbox augmentation to the bounding box.

@param img: Bounding box to which resize is applied.
@type img: BoxType
@param pad_top: Number of pixels to pad at the top.
@type bbox: BoxType
@param bbox: Bounding box to which resize is applied.
@type pad_top: int
@param pad_bottom: Number of pixels to pad at the bottom.
@param pad_top: Number of pixels to pad at the top.
@type pad_bottom: int
@param pad_left: Number of pixels to pad on the left.
@param pad_bottom: Number of pixels to pad at the bottom.
@type pad_left: int
@param pad_right: Number of pixels to pad on the right.
@param pad_left: Number of pixels to pad on the left.
@type pad_right: int
@param params: Additional parameters for the padding operation.
@param pad_right: Number of pixels to pad on the right.
@type params: Any
@return: Bounding box with applied letterbox resize.
@param params: Additional parameters for the padding operation.
@rtype: BoxType
@return: Bounding box with applied letterbox resize.
"""

x_min, y_min, x_max, y_max = denormalize_bbox(
Expand Down Expand Up @@ -245,29 +245,29 @@ def apply_to_keypoint(
pad_bottom: int,
pad_left: int,
pad_right: int,
**params,
**kwargs,
) -> KeypointType:
"""Applies letterbox augmentation to the keypoint.

@param img: Keypoint to which resize is applied.
@type img: KeypointType
@param pad_top: Number of pixels to pad at the top.
@type keypoint: KeypointType
@param keypoint: Keypoint to which resize is applied.
@type pad_top: int
@param pad_bottom: Number of pixels to pad at the bottom.
@param pad_top: Number of pixels to pad at the top.
@type pad_bottom: int
@param pad_left: Number of pixels to pad on the left.
@param pad_bottom: Number of pixels to pad at the bottom.
@type pad_left: int
@param pad_right: Number of pixels to pad on the right.
@param pad_left: Number of pixels to pad on the left.
@type pad_right: int
@param params: Additional parameters for the padding operation.
@type params: Any
@return: Keypoint with applied letterbox resize.
@param pad_right: Number of pixels to pad on the right.
@type kwargs: Any
@param kwargs: Additional parameters for the padding operation.
@rtype: KeypointType
@return: Keypoint with applied letterbox resize.
"""

x, y, angle, scale = keypoint[:4]
scale_x = (self.width - pad_left - pad_right) / params["cols"]
scale_y = (self.height - pad_top - pad_bottom) / params["rows"]
scale_x = (self.width - pad_left - pad_right) / kwargs["cols"]
scale_y = (self.height - pad_top - pad_bottom) / kwargs["rows"]
new_x = (x * scale_x) + pad_left
new_y = (y * scale_y) + pad_top
# if keypoint is in the padding then set coordinates to -1
Expand All @@ -286,8 +286,8 @@ def apply_to_keypoint(
def get_transform_init_args_names(self) -> Tuple[str, ...]:
"""Gets the default arguments for the letterbox augmentation.

@return: The string keywords of the arguments.
@rtype: Tuple[str, ...]
@return: The string keywords of the arguments.
"""

return (
Expand All @@ -303,14 +303,14 @@ def _out_of_bounds(
) -> bool:
""" "Check if the given value is outside the specified limits.

@param value: The value to be checked.
@type value: float
@param min_limit: Minimum limit.
@param value: The value to be checked.
@type min_limit: float
@param max_limit: Maximum limit.
@param min_limit: Minimum limit.
@type max_limit: float
@param max_limit: Maximum limit.
@rtype: bool
@return: True if the value is outside the specified limits,
False otherwise.
@rtype: bool
"""
return value < min_limit or value > max_limit
66 changes: 33 additions & 33 deletions luxonis_ml/data/augmentations/custom/mixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ def __init__(
annotations into one. If images are not of same size then second
one is first resized to match the first one.

@type alpha: Union[float, Tuple[float, float]]
@param alpha: Mixing coefficient, either a single float or a
tuple representing the range. Defaults to 0.5.
@type alpha: Union[float, Tuple[float, float]], optional
tuple representing the range. Defaults to C{0.5}.
@type out_batch_size: int
@param out_batch_size: Number of output images in the batch.
Defaults to 1.
@type out_batch_size: int, optional
Defaults to C{1}.
@type always_apply: bool
@param always_apply: Whether to always apply the transform.
Defaults to False.
@type always_apply: bool, optional
@param p: Probability of applying the transform. Defaults to
0.5.
Defaults to C{False}.
@type p: float, optional
@param p: Probability of applying the transform. Defaults to
C{0.5}.
"""
super().__init__(batch_size=2, always_apply=always_apply, p=p)

Expand All @@ -44,17 +44,17 @@ def __init__(
def get_transform_init_args_names(self) -> Tuple[str, ...]:
"""Gets the default arguments for the mixup augmentation.

@return: The string keywords of the arguments.
@rtype: Tuple[str, ...]
@return: The string keywords of the arguments.
"""
return ("alpha", "out_batch_size")

@property
def targets_as_params(self) -> List[str]:
"""List of augmentation targets.

@return: Output list of augmentation targets.
@rtype: List[str]
@return: Output list of augmentation targets.
"""
return ["image_batch"]

Expand All @@ -66,15 +66,15 @@ def apply_to_image_batch(
) -> List[np.ndarray]:
"""Applies the transformation to a batch of images.

@type image_batch: List[np.ndarray]
@param image_batch: Batch of input images to which the
transformation is applied.
@type image_batch: List[np.ndarray]
@param image_shapes: Shapes of the input images in the batch.
@type image_shapes: List[Tuple[int, int]]
@param params: Additional parameters for the transformation.
@param image_shapes: Shapes of the input images in the batch.
@type params: Any
@return: List of transformed images.
@param params: Additional parameters for the transformation.
@rtype: List[np.ndarray]
@return: List of transformed images.
"""
image1 = image_batch[0]
# resize second image to size of the first one
Expand All @@ -101,15 +101,15 @@ def apply_to_mask_batch(
) -> List[np.ndarray]:
"""Applies the transformation to a batch of masks.

@param image_batch: Batch of input masks to which the
@type mask_batch: List[np.ndarray]
@param mask_batch: Batch of input masks to which the
transformation is applied.
@type image_batch: List[np.ndarray]
@param image_shapes: Shapes of the input images in the batch.
@type image_shapes: List[Tuple[int, int]]
@param params: Additional parameters for the transformation.
@param image_shapes: Shapes of the input images in the batch.
@type params: Any
@return: List of transformed masks.
@param params: Additional parameters for the transformation.
@rtype: List[np.ndarray]
@return: List of transformed masks.
"""
mask1 = mask_batch[0]
mask2 = cv2.resize(
Expand All @@ -127,39 +127,39 @@ def apply_to_bboxes_batch(
self,
bboxes_batch: List[BoxType],
image_shapes: List[Tuple[int, int]],
**params,
**kwargs,
) -> List[BoxType]:
"""Applies the transformation to a batch of bboxes.

@param image_batch: Batch of input bboxes to which the
@type bboxes_batch: List[BoxType]
@param bboxes_batch: Batch of input bboxes to which the
transformation is applied.
@type image_batch: List[BoxType]
@param image_shapes: Shapes of the input images in the batch.
@type image_shapes: List[Tuple[int, int]]
@param params: Additional parameters for the transformation.
@type params: Any
@return: List of transformed bboxes.
@param image_shapes: Shapes of the input images in the batch.
@type kwargs: Any
@param kwargs: Additional parameters for the transformation.
@rtype: List[BoxType]
@return: List of transformed bboxes.
"""
return [bboxes_batch[0] + bboxes_batch[1]]

def apply_to_keypoints_batch(
self,
keypoints_batch: List[KeypointType],
image_shapes: List[Tuple[int, int]],
**params,
**kwargs,
) -> List[KeypointType]:
"""Applies the transformation to a batch of keypoints.

@param image_batch: Batch of input keypoints to which the
@type keypoints_batch: List[BoxType]
@param keypoints_batch: Batch of input keypoints to which the
transformation is applied.
@type image_batch: List[BoxType]
@param image_shapes: Shapes of the input images in the batch.
@type image_shapes: List[Tuple[int, int]]
@param params: Additional parameters for the transformation.
@type params: Any
@return: List of transformed keypoints.
@param image_shapes: Shapes of the input images in the batch.
@type kwargs: Any
@param kwargs: Additional parameters for the transformation.
@rtype: List[BoxType]
@return: List of transformed keypoints.
"""
scaled_kpts2 = []
scale_x = image_shapes[0][1] / image_shapes[1][1]
Expand Down
Loading
Loading