From 9268747cad293ee2bb3070e88a941600edcddfa3 Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 8 Nov 2024 17:45:11 +0100 Subject: [PATCH 1/2] fixed warnings --- luxonis_ml/data/__init__.py | 2 +- .../data/augmentations/batch_compose.py | 8 +- .../augmentations/custom/letterbox_resize.py | 100 +++++------ luxonis_ml/data/augmentations/custom/mixup.py | 66 ++++---- .../data/augmentations/custom/mosaic.py | 158 +++++++++--------- luxonis_ml/data/augmentations/utils.py | 2 - luxonis_ml/data/datasets/annotation.py | 6 +- luxonis_ml/data/datasets/base_dataset.py | 15 +- luxonis_ml/data/datasets/luxonis_dataset.py | 12 +- luxonis_ml/data/datasets/source.py | 2 +- luxonis_ml/data/loaders/base_loader.py | 14 +- luxonis_ml/data/loaders/luxonis_loader.py | 4 +- luxonis_ml/data/parsers/base_parser.py | 7 +- 13 files changed, 201 insertions(+), 195 deletions(-) diff --git a/luxonis_ml/data/__init__.py b/luxonis_ml/data/__init__.py index 76d91449..684fdb96 100644 --- a/luxonis_ml/data/__init__.py +++ b/luxonis_ml/data/__init__.py @@ -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 diff --git a/luxonis_ml/data/augmentations/batch_compose.py b/luxonis_ml/data/augmentations/batch_compose.py index fbea3111..5969ee0d 100644 --- a/luxonis_ml/data/augmentations/batch_compose.py +++ b/luxonis_ml/data/augmentations/batch_compose.py @@ -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 @@ -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 diff --git a/luxonis_ml/data/augmentations/custom/letterbox_resize.py b/luxonis_ml/data/augmentations/custom/letterbox_resize.py index 95884bc8..073e5c57 100644 --- a/luxonis_ml/data/augmentations/custom/letterbox_resize.py +++ b/luxonis_ml/data/augmentations/custom/letterbox_resize.py @@ -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) @@ -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( @@ -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( @@ -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( @@ -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 @@ -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 ( @@ -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 diff --git a/luxonis_ml/data/augmentations/custom/mixup.py b/luxonis_ml/data/augmentations/custom/mixup.py index 17dce2b7..866f28a9 100644 --- a/luxonis_ml/data/augmentations/custom/mixup.py +++ b/luxonis_ml/data/augmentations/custom/mixup.py @@ -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) @@ -44,8 +44,8 @@ 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") @@ -53,8 +53,8 @@ def get_transform_init_args_names(self) -> Tuple[str, ...]: 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"] @@ -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 @@ -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( @@ -127,19 +127,19 @@ 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]] @@ -147,19 +147,19 @@ 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] diff --git a/luxonis_ml/data/augmentations/custom/mosaic.py b/luxonis_ml/data/augmentations/custom/mosaic.py index a0c912fc..9e16538a 100644 --- a/luxonis_ml/data/augmentations/custom/mosaic.py +++ b/luxonis_ml/data/augmentations/custom/mosaic.py @@ -35,30 +35,32 @@ def __init__( have different widths and heights. The output is cropped around the intersection point of the four images with the size (out_with x out_height). If the mosaic image is smaller than - width x height, the gap is filled by the fill_value. + width x height, the gap is filled by the C{fill_value}. - @param out_height: Output image height. The mosaic image is cropped by this height around the mosaic center. - If the size of the mosaic image is smaller than this value the gap is filled by the `value`. @type out_height: int - - @param out_width: Output image width. The mosaic image is cropped by this height around the mosaic center. - If the size of the mosaic image is smaller than this value the gap is filled by the `value`. + @param out_height: Output image height. The mosaic image is + cropped by this height around the mosaic center. If the size + of the mosaic image is smaller than this value the gap is + filled by the C{value}. @type out_width: int - - @param value: Padding value. Defaults to None. - @type value: Optional[Union[int, float, List[int], List[float]]], optional - - @param out_batch_size: Number of output images in the batch. Defaults to 1. - @type out_batch_size: int, optional - - @param mask_value: Padding value for masks. Defaults to None. - @type mask_value: Optional[Union[int, float, List[int], List[float]]], optional - - @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. - @type p: float, optional + @param out_width: Output image width. The mosaic image is + cropped by this height around the mosaic center. If the size + of the mosaic image is smaller than this value the gap is + filled by the C{value}. + @type value: Optional[Union[int, float, List[int], List[float]]] + @param value: Padding value. Defaults to C{None}. + @type out_batch_size: int + @param out_batch_size: Number of output images in the batch. + Defaults to C{1}. + @type mask_value: Optional[Union[int, float, List[int], + List[float]]] + @param mask_value: Padding value for masks. Defaults to C{None}. + @type always_apply: bool + @param always_apply: Whether to always apply the transform. + Defaults to C{False}. + @type p: float + @param p: Probability of applying the transform. Defaults to + C{0.5}. """ super().__init__(batch_size=4, always_apply=always_apply, p=p) @@ -86,8 +88,8 @@ 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 ( "out_height", @@ -109,8 +111,8 @@ def _generate_random_crop_center(self) -> Tuple[int, int]: def targets_as_params(self): """List of augmentation targets. - @return: Output list of augmentation targets. @rtype: List[str] + @return: Output list of augmentation targets. """ return ["image_batch"] @@ -124,19 +126,19 @@ 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 indices: Indices of images in the batch. @type indices: List[Tuple[int, int]] - @param params: Additional parameters for the transformation. + @param indices: Indices of images in the batch. @type params: Any - @param x_crop: x-coordinate of the croping start point + @param params: Additional parameters for the transformation. @type x_crop: int - @param y_crop: y-coordinate of the croping start point + @param x_crop: x-coordinate of the croping start point @type y_crop: int - @return: List of transformed images. + @param y_crop: y-coordinate of the croping start point @rtype: List[np.ndarray] + @return: List of transformed images. """ output_batch = [] for i_batch in range(self.out_batch_size): @@ -165,19 +167,19 @@ def apply_to_mask_batch( ) -> List[np.ndarray]: """Applies the transformation to a batch of masks. + @type mask_batch: List[np.ndarray] @param mask_batch: Batch of input masks to which the transformation is applied. - @type mask_batch: List[np.ndarray] - @param indices: Indices of images in the batch. @type indices: List[Tuple[int, int]] - @param params: Additional parameters for the transformation. + @param indices: Indices of images in the batch. @type params: Any - @param x_crop: x-coordinate of the croping start point + @param params: Additional parameters for the transformation. @type x_crop: int - @param y_crop: y-coordinate of the croping start point + @param x_crop: x-coordinate of the croping start point @type y_crop: int - @return: List of transformed masks. + @param y_crop: y-coordinate of the croping start point @rtype: List[np.ndarray] + @return: List of transformed masks. """ output_batch = [] for i_batch in range(self.out_batch_size): @@ -207,21 +209,21 @@ def apply_to_bboxes_batch( ) -> List[BoxType]: """Applies the transformation to a batch of bboxes. + @type bboxes_batch: List[BboxType] @param bboxes_batch: Batch of input bboxes to which the transformation is applied. - @type bboxes_batch: List[BboxType] - @param indices: Indices of images in the batch. @type indices: List[Tuple[int, int]] - @param image_shapes: Shapes of the input images in the batch. + @param indices: Indices of 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 - @param x_crop: x-coordinate of the croping start point + @param params: Additional parameters for the transformation. @type x_crop: int - @param y_crop: y-coordinate of the croping start point + @param x_crop: x-coordinate of the croping start point @type y_crop: int - @return: List of transformed bboxes. + @param y_crop: y-coordinate of the croping start point @rtype: List[BoxType] + @return: List of transformed bboxes. """ output_batch = [] for i_batch in range(self.out_batch_size): @@ -251,7 +253,7 @@ def apply_to_bboxes_batch( def apply_to_keypoints_batch( self, - keyboints_batch: List[KeypointType], + keypoints_batch: List[KeypointType], indices: List[int], image_shapes: List[Tuple[int, int]], x_crop: int, @@ -260,28 +262,28 @@ def apply_to_keypoints_batch( ) -> List[KeypointType]: """Applies the transformation to a batch of keypoints. + @type keypoints_batch: List[KeypointType] @param keypoints_batch: Batch of input keypoints to which the transformation is applied. - @type keypoints_batch: List[KeypointType] - @param indices: Indices of images in the batch. @type indices: List[Tuple[int, int]] - @param image_shapes: Shapes of the input images in the batch. + @param indices: Indices of 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 - @param x_crop: x-coordinate of the croping start point + @param params: Additional parameters for the transformation. @type x_crop: int - @param y_crop: y-coordinate of the croping start point + @param x_crop: x-coordinate of the croping start point @type y_crop: int - @return: List of transformed keypoints. + @param y_crop: y-coordinate of the croping start point @rtype: List[KeypointType] + @return: List of transformed keypoints. """ output_batch = [] for i_batch in range(self.out_batch_size): idx_chunk = indices[ self.n_tiles * i_batch : self.n_tiles * (i_batch + 1) ] - keypoints_chunk = [keyboints_batch[i] for i in idx_chunk] + keypoints_chunk = [keypoints_batch[i] for i in idx_chunk] shape_chunk = [image_shapes[i] for i in idx_chunk] new_keypoints = [] for i in range(self.n_tiles): @@ -307,11 +309,11 @@ def get_params_dependent_on_targets( ) -> Dict[str, Any]: """Get parameters dependent on the targets. - @param params: Dictionary containing parameters. @type params: Dict[str, Any] + @param params: Dictionary containing parameters. + @rtype: Dict[str, Any] @return: Dictionary containing parameters dependent on the targets. - @rtype: Dict[str, Any] """ image_batch = params["image_batch"] n = len(image_batch) @@ -343,21 +345,21 @@ def mosaic4( have the same number of channels but can have different widths and heights. The gaps are filled by the value. + @type image_batch: List[np.ndarray] @param image_batch: Image list. The length should be four. Each image can has different size. - @type image_batch: List[np.ndarray] - @param height: Height of output mosaic image @type height: int - @param width: Width of output mosaic image + @param height: Height of output mosaic image @type width: int - @param value: Padding value + @param width: Width of output mosaic image @type value: Optional[int] - @param x_crop: x-coordinate of the croping start point + @param value: Padding value @type x_crop: int - @param y_crop: y-coordinate of the croping start point + @param x_crop: x-coordinate of the croping start point @type y_crop: int - @return: Final output image + @param y_crop: y-coordinate of the croping start point @rtype: np.ndarray + @return: Final output image """ N_TILES = 4 if len(image_batch) != N_TILES: @@ -455,25 +457,25 @@ def bbox_mosaic4( in a 2x2 grid mosaic, shifting their coordinates based on the tile's relative position within the mosaic. - @param bbox: Bounding box coordinates to be transformed. @type bbox: BoxInternalType - @param rows: Height of the original image. + @param bbox: Bounding box coordinates to be transformed. @type rows: int - @param cols: Width of the original image. + @param rows: Height of the original image. @type cols: int + @param cols: Width of the original image. + @type position_index: int @param position_index: Position of the image in the 2x2 grid. (0 = top-left, 1 = top-right, 2 = bottom-left, 3 = bottom-right). - @type position_index: int - @param height: Height of the final output mosaic image. @type height: int - @param width: Width of the final output mosaic image. + @param height: Height of the final output mosaic image. @type width: int - @param x_crop: x-coordinate of the croping start point + @param width: Width of the final output mosaic image. @type x_crop: int - @param y_crop: y-coordinate of the croping start point + @param x_crop: x-coordinate of the croping start point @type y_crop: int - @return: Transformed bounding box coordinates. + @param y_crop: y-coordinate of the croping start point @rtype: BoxInternalType + @return: Transformed bounding box coordinates. """ bbox = denormalize_bbox(bbox, rows, cols) @@ -519,26 +521,26 @@ def keypoint_mosaic4( one of the 2x2 mosaic grid cells, with shifts relative to the mosaic center. + @type keypoint: KeypointInternalType @param keypoint: Keypoint coordinates and attributes (x, y, angle, scale). - @type keypoint: KeypointInternalType - @param rows: Height of the original image. @type rows: int - @param cols: Width of the original image. + @param rows: Height of the original image. @type cols: int + @param cols: Width of the original image. + @type position_index: int @param position_index: Position of the image in the 2x2 grid. (0 = top-left, 1 = top-right, 2 = bottom-left, 3 = bottom-right). - @type position_index: int - @param height: Height of the final output mosaic image. @type height: int - @param width: Width of the final output mosaic image. + @param height: Height of the final output mosaic image. @type width: int - @param x_crop: x-coordinate of the croping start point + @param width: Width of the final output mosaic image. @type x_crop: int - @param y_crop: y-coordinate of the croping start point + @param x_crop: x-coordinate of the croping start point @type y_crop: int - @return: Adjusted keypoint coordinates. + @param y_crop: y-coordinate of the croping start point @rtype: KeypointInternalType + @return: Adjusted keypoint coordinates. """ x, y, angle, scale = keypoint diff --git a/luxonis_ml/data/augmentations/utils.py b/luxonis_ml/data/augmentations/utils.py index cc616997..0a6b58f6 100644 --- a/luxonis_ml/data/augmentations/utils.py +++ b/luxonis_ml/data/augmentations/utils.py @@ -213,8 +213,6 @@ def __call__( @type data: List[Tuple[np.ndarray, Dict[LabelType, np.ndarray]]] @param data: Data with list of input images and their annotations - @type nc: int - @param nc: Number of classes @type ns: int @param ns: Number of segmentation classes @type nk: int diff --git a/luxonis_ml/data/datasets/annotation.py b/luxonis_ml/data/datasets/annotation.py index 9a11bc76..61b1d5d4 100644 --- a/luxonis_ml/data/datasets/annotation.py +++ b/luxonis_ml/data/datasets/annotation.py @@ -76,7 +76,7 @@ class Annotation(ABC, BaseModelExtraForbid): @type instance_id: int @ivar instance_id: The instance id of the annotation. This determines the order in which individual instances are loaded in - L{LuxonisLoader}. + L{luxonis_ml.data.LuxonisLoader}. @type _label_type: ClassVar[L{LabelType}] @ivar _label_type: The label type of the annotation. """ @@ -482,7 +482,7 @@ class ArrayAnnotation(Annotation): All instances of this annotation must have the same shape. - @type path: L{FilePath} + @type path: FilePath @ivar path: The path to the numpy array saved as a C{.npy} file. """ @@ -546,7 +546,7 @@ def combine_to_numpy( class DatasetRecord(BaseModelExtraForbid): """A record of an image and its annotation. - @type file: L{FilePath} + @type file: FilePath @ivar file: A path to the image. @type annotation: Optional[Annotation] @ivar annotation: The annotation for the image. diff --git a/luxonis_ml/data/datasets/base_dataset.py b/luxonis_ml/data/datasets/base_dataset.py index 57f6a832..5a36e08e 100644 --- a/luxonis_ml/data/datasets/base_dataset.py +++ b/luxonis_ml/data/datasets/base_dataset.py @@ -3,12 +3,11 @@ from typing_extensions import TypeAlias +from luxonis_ml.data.datasets.annotation import DatasetRecord +from luxonis_ml.data.datasets.source import LuxonisSource from luxonis_ml.utils import AutoRegisterMeta, Registry from luxonis_ml.utils.filesystem import PathType -from .annotation import DatasetRecord -from .source import LuxonisSource - DATASETS_REGISTRY: Registry[Type["BaseDataset"]] = Registry(name="datasets") @@ -24,7 +23,10 @@ class BaseDataset( @property @abstractmethod def identifier(self) -> str: - """The unique identifier for the dataset.""" + """The unique identifier for the dataset. + + @type: str + """ pass @abstractmethod @@ -66,9 +68,6 @@ def get_classes(self) -> Tuple[List[str], Dict[str, List[str]]]: """Gets overall classes in the dataset and classes according to computer vision task. - @type sync_mode: bool - @param sync_mode: If C{True}, reads classes from remote storage. - If C{False}, classes are read locally. @rtype: Tuple[List[str], Dict] @return: A combined list of classes for all tasks and a dictionary mapping tasks to the classes used in each task. @@ -121,7 +120,7 @@ def add( ) -> None: """Write annotations to parquet files. - @type generator: L{DatasetGenerator} + @type generator: L{DatasetIterator} @param generator: A Python iterator that yields either instances of L{DatasetRecord} or a dictionary that can be converted to L{DatasetRecord}. diff --git a/luxonis_ml/data/datasets/luxonis_dataset.py b/luxonis_ml/data/datasets/luxonis_dataset.py index ee7c8c28..4afbefee 100644 --- a/luxonis_ml/data/datasets/luxonis_dataset.py +++ b/luxonis_ml/data/datasets/luxonis_dataset.py @@ -818,9 +818,15 @@ def exists( @type dataset_name: str @param dataset_name: Name of the dataset to check - @type remote: bool - @param remote: Whether to check if the dataset exists in the - cloud + @type team_id: Optional[str] + @param team_id: Optional team identifier + @type bucket_storage: BucketStorage + @param bucket_storage: Underlying bucket storage from C{local}, + C{S3}, or C{GCS}. Default is C{local}. + @type bucket: Optional[str] + @param bucket: Name of the bucket. Default is C{None}. + @rtype: bool + @return: Whether the dataset exists """ return dataset_name in LuxonisDataset.list_datasets( team_id, bucket_storage, bucket diff --git a/luxonis_ml/data/datasets/source.py b/luxonis_ml/data/datasets/source.py index 57174abe..41dc792b 100644 --- a/luxonis_ml/data/datasets/source.py +++ b/luxonis_ml/data/datasets/source.py @@ -71,7 +71,7 @@ def __init__( For example, with an U{OAK-D}, you can have a source with 4 image - components: rgb (color), left (mono), right (mono), and depth. + components: C{rgb} (color), C{left} (mono), C{right} (mono), and C{depth}. @type name: str @param name: A recognizable name for the source. Defaults to "default". diff --git a/luxonis_ml/data/loaders/base_loader.py b/luxonis_ml/data/loaders/base_loader.py index ea33b355..71f72983 100644 --- a/luxonis_ml/data/loaders/base_loader.py +++ b/luxonis_ml/data/loaders/base_loader.py @@ -9,14 +9,14 @@ from ..utils.enums import LabelType Labels: TypeAlias = Dict[str, Tuple[np.ndarray, LabelType]] -"""C{Labels} is a dictionary mappping task names to their L{LabelType} -and annotations as L{numpy arrays}.""" +"""C{Labels} is a dictionary mappping task names to a tuple composed of +the annotation as C{np.ndarray} and its corresponding C{LabelType}""" LuxonisLoaderOutput: TypeAlias = Tuple[np.ndarray, Labels] -"""C{LuxonisLoaderOutput} is a tuple of an image as a L{numpy -array} and a dictionary of task group names and their -annotations as L{Annotations}.""" +"""C{LuxonisLoaderOutput} is a tuple of an image as a C{np.ndarray>} and +a dictionary of task group names and their annotations as +L{Annotations}.""" LOADERS_REGISTRY: Registry[Type["BaseLoader"]] = Registry(name="loaders") @@ -44,7 +44,7 @@ def __getitem__(self, idx: int) -> LuxonisLoaderOutput: @type idx: int @param idx: Index of the sample to load. - @rtype: LuxonisLoaderOutput + @rtype: L{LuxonisLoaderOutput} @return: Sample's data in L{LuxonisLoaderOutput} format. """ pass @@ -52,7 +52,7 @@ def __getitem__(self, idx: int) -> LuxonisLoaderOutput: def __iter__(self) -> Iterator[LuxonisLoaderOutput]: """Iterates over the dataset. - @rtype: Iterator + @rtype: Iterator[L{LuxonisLoaderOutput}] @return: Iterator over the dataset. """ for i in range(len(self)): diff --git a/luxonis_ml/data/loaders/luxonis_loader.py b/luxonis_ml/data/loaders/luxonis_loader.py index 4c66c39c..c6245aaf 100644 --- a/luxonis_ml/data/loaders/luxonis_loader.py +++ b/luxonis_ml/data/loaders/luxonis_loader.py @@ -259,8 +259,8 @@ def _load_image_with_annotations( @type idx: int @param idx: Index of the image - @rtype: Tuple[L{np.ndarray}, dict] - @return: Image as L{np.ndarray} in RGB format and a dictionary + @rtype: Tuple[np.ndarray, Labels] + @return: Image as C{np.ndarray} in RGB format and a dictionary with all the present annotations """ diff --git a/luxonis_ml/data/parsers/base_parser.py b/luxonis_ml/data/parsers/base_parser.py index 0d5c2593..84207155 100644 --- a/luxonis_ml/data/parsers/base_parser.py +++ b/luxonis_ml/data/parsers/base_parser.py @@ -55,11 +55,12 @@ def from_dir( @type dataset_dir: str @param dataset_dir: Path to source dataset directory. - @type parser_kwargs: Dict[str, Any] - @param parser_kwargs: Additional kwargs for specific parser + @type kwargs: Any + @param kwargs: Additional arguments for a specific parser implementation. @rtype: Tuple[List[str], List[str], List[str]] - @return: Tuple with added images for train, val and test splits. + @return: Tuple with added images for C{train}, C{val} and + C{test} splits. """ pass From 78ba32022e82b73b27d907753bf5243b3de89c3f Mon Sep 17 00:00:00 2001 From: Martin Kozlovsky Date: Fri, 8 Nov 2024 17:53:47 +0100 Subject: [PATCH 2/2] formatting --- luxonis_ml/data/datasets/annotation.py | 30 ++++++++++++++------- luxonis_ml/data/datasets/base_dataset.py | 6 ++--- luxonis_ml/data/datasets/luxonis_dataset.py | 21 ++++++++++----- luxonis_ml/data/loaders/base_loader.py | 2 +- luxonis_ml/data/loaders/luxonis_loader.py | 11 ++++---- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/luxonis_ml/data/datasets/annotation.py b/luxonis_ml/data/datasets/annotation.py index 61b1d5d4..9037d0d6 100644 --- a/luxonis_ml/data/datasets/annotation.py +++ b/luxonis_ml/data/datasets/annotation.py @@ -77,7 +77,7 @@ class Annotation(ABC, BaseModelExtraForbid): @ivar instance_id: The instance id of the annotation. This determines the order in which individual instances are loaded in L{luxonis_ml.data.LuxonisLoader}. - @type _label_type: ClassVar[L{LabelType}] + @type _label_type: ClassVar[LabelType] @ivar _label_type: The label type of the annotation. """ @@ -110,7 +110,17 @@ def combine_to_numpy( width: int, ) -> np.ndarray: """Combines multiple instance annotations into a single numpy - array.""" + array. + + @type annotations: List[Annotation] + @param annotations: List of annotations to combine. + @type class_mapping: Dict[str, int] + @param class_mapping: Mapping of class names to class indices. + @type height: int + @param height: The height of the image. + @type width: int + @param width: The width of the image. + """ pass @@ -138,14 +148,14 @@ class BBoxAnnotation(Annotation): @type x: float @ivar x: The top-left x coordinate of the bounding box. Normalized - to [0, 1]. + to M{[0, 1]}. @type y: float @ivar y: The top-left y coordinate of the bounding box. Normalized - to [0, 1]. + to M{[0, 1]}. @type w: float - @ivar w: The width of the bounding box. Normalized to [0, 1]. + @ivar w: The width of the bounding box. Normalized to M{[0, 1]}. @type h: float - @ivar h: The height of the bounding box. Normalized to [0, 1]. + @ivar h: The height of the bounding box. Normalized to M{[0, 1]}. """ type_: Literal["boundingbox"] = Field("boundingbox", alias="type") @@ -211,11 +221,11 @@ def combine_to_numpy( class KeypointAnnotation(Annotation): """Keypoint annotation. - Values are normalized to [0, 1] based on the image size. + Values are normalized to M{[0, 1]} based on the image size. @type keypoints: List[Tuple[float, float, L{KeypointVisibility}]] @ivar keypoints: List of keypoints. Each keypoint is a tuple of (x, y, visibility). - x and y are normalized to [0, 1]. visibility is one of {0, 1, 2} where: + x and y are normalized to M{[0, 1]}. visibility is one of M{0}, M{1}, or M{2} where: - 0: Not visible / not labeled - 1: Occluded - 2: Visible @@ -430,8 +440,8 @@ class PolylineSegmentationAnnotation(SegmentationAnnotation): @type points: List[Tuple[float, float]] @ivar points: List of points that define the polyline. Each point is - a tuple of (x, y). x and y are normalized to [0, 1] based on the - image size. + a tuple of (x, y). x and y are normalized to M{[0, 1]} based on + the image size. """ type_: Literal["polyline"] = Field("polyline", alias="type") diff --git a/luxonis_ml/data/datasets/base_dataset.py b/luxonis_ml/data/datasets/base_dataset.py index 5a36e08e..066faab9 100644 --- a/luxonis_ml/data/datasets/base_dataset.py +++ b/luxonis_ml/data/datasets/base_dataset.py @@ -44,7 +44,7 @@ def update_source(self, source: LuxonisSource) -> None: LuxonisSource. @type source: L{LuxonisSource} - @param source: The new L{LuxonisSource} to replace the old one. + @param source: The new C{LuxonisSource} to replace the old one. """ pass @@ -122,8 +122,8 @@ def add( @type generator: L{DatasetIterator} @param generator: A Python iterator that yields either instances - of L{DatasetRecord} or a dictionary that can be converted to - L{DatasetRecord}. + of C{DatasetRecord} or a dictionary that can be converted to + C{DatasetRecord}. @type batch_size: int @param batch_size: The number of annotations generated before processing. This can be set to a lower value to reduce diff --git a/luxonis_ml/data/datasets/luxonis_dataset.py b/luxonis_ml/data/datasets/luxonis_dataset.py index 4afbefee..c79f19b8 100644 --- a/luxonis_ml/data/datasets/luxonis_dataset.py +++ b/luxonis_ml/data/datasets/luxonis_dataset.py @@ -64,8 +64,8 @@ def __init__( @type bucket_type: BucketType @param bucket_type: Whether to use external cloud buckets @type bucket_storage: BucketStorage - @param bucket_storage: Underlying bucket storage from local, S3, - or GCS + @param bucket_storage: Underlying bucket storage. Can be one of + C{local}, C{S3}, or C{GCS}. @type delete_existing: bool @param delete_existing: Whether to delete a dataset with the same name if it exists @@ -283,8 +283,8 @@ def update_source(self, source: LuxonisSource) -> None: """Updates underlying source of the dataset with a new L{LuxonisSource}. - @type source: L{LuxonisSource} - @param source: The new L{LuxonisSource} to replace the old one. + @type source: LuxonisSource + @param source: The new C{LuxonisSource} to replace the old one. """ self.metadata["source"] = source.to_document() @@ -826,7 +826,7 @@ def exists( @type bucket: Optional[str] @param bucket: Name of the bucket. Default is C{None}. @rtype: bool - @return: Whether the dataset exists + @return: Whether the dataset exists. """ return dataset_name in LuxonisDataset.list_datasets( team_id, bucket_storage, bucket @@ -840,8 +840,15 @@ def list_datasets( ) -> List[str]: """Returns a dictionary of all datasets. - @rtype: Dict - @return: Dictionary of all datasets + @type team_id: Optional[str] + @param team_id: Optional team identifier + @type bucket_storage: BucketStorage + @param bucket_storage: Underlying bucket storage from C{local}, + C{S3}, or C{GCS}. Default is C{local}. + @type bucket: Optional[str] + @param bucket: Name of the bucket. Default is C{None}. + @rtype: List[str] + @return: List of all dataset names. """ base_path = environ.LUXONISML_BASE_PATH diff --git a/luxonis_ml/data/loaders/base_loader.py b/luxonis_ml/data/loaders/base_loader.py index 71f72983..8d7256f6 100644 --- a/luxonis_ml/data/loaders/base_loader.py +++ b/luxonis_ml/data/loaders/base_loader.py @@ -45,7 +45,7 @@ def __getitem__(self, idx: int) -> LuxonisLoaderOutput: @type idx: int @param idx: Index of the sample to load. @rtype: L{LuxonisLoaderOutput} - @return: Sample's data in L{LuxonisLoaderOutput} format. + @return: Sample's data in C{LuxonisLoaderOutput} format. """ pass diff --git a/luxonis_ml/data/loaders/luxonis_loader.py b/luxonis_ml/data/loaders/luxonis_loader.py index c6245aaf..c448abf0 100644 --- a/luxonis_ml/data/loaders/luxonis_loader.py +++ b/luxonis_ml/data/loaders/luxonis_loader.py @@ -30,10 +30,10 @@ def __init__( """A loader class used for loading data from L{LuxonisDataset}. @type dataset: LuxonisDataset - @param dataset: LuxonisDataset to use + @param dataset: Instance of C{LuxonisDataset} to use. @type view: Union[str, List[str]] @param view: What splits to use. Can be either a single split or - a list of splits. Defaults to "train". + a list of splits. Defaults to C{"train"}. @type stream: bool @param stream: Flag for data streaming. Defaults to C{False}. @type augmentations: Optional[luxonis_ml.loader.Augmentations] @@ -141,7 +141,7 @@ def __len__(self) -> int: """Returns length of the dataset. @rtype: int - @return: Length of dataset. + @return: Length of the loader. """ return len(self.instances) @@ -150,9 +150,8 @@ def __getitem__(self, idx: int) -> LuxonisLoaderOutput: annotations. @type idx: int - @param idx: The (often random) integer index to retrieve a - sample from the dataset. - @rtype: LuxonisLoaderOutput + @param idx: The integer index of the sample to retrieve. + @rtype: L{LuxonisLoaderOutput} @return: The loader ouput consisting of the image and a dictionary defining its annotations. """