targetran
Advanced tools
+3
-1
| Metadata-Version: 2.1 | ||
| Name: targetran | ||
| Version: 0.11.9 | ||
| Version: 0.12.0 | ||
| Summary: Target transformation for data augmentation in objection detection | ||
@@ -195,2 +195,3 @@ Home-page: https://github.com/bhky/targetran | ||
| selected_probabilities=[0.5, 0.0, 0.3, 0.2, 0.0], # Must sum up to 1.0, if given. | ||
| keep_order=True, # If True, the selected steps must be performed in the given order. | ||
| probability=1.0 # Probability to apply this single combined transformation. | ||
@@ -302,2 +303,3 @@ ) | ||
| selected_probabilities=[0.5, 0.0, 0.3, 0.2, 0.0], # Must sum up to 1.0, if given. | ||
| keep_order=True, # If True, the selected steps must be performed in the given order. | ||
| probability=1.0 # Probability to apply this single combined transformation. | ||
@@ -304,0 +306,0 @@ ) |
+2
-0
@@ -181,2 +181,3 @@  | ||
| selected_probabilities=[0.5, 0.0, 0.3, 0.2, 0.0], # Must sum up to 1.0, if given. | ||
| keep_order=True, # If True, the selected steps must be performed in the given order. | ||
| probability=1.0 # Probability to apply this single combined transformation. | ||
@@ -288,2 +289,3 @@ ) | ||
| selected_probabilities=[0.5, 0.0, 0.3, 0.2, 0.0], # Must sum up to 1.0, if given. | ||
| keep_order=True, # If True, the selected steps must be performed in the given order. | ||
| probability=1.0 # Probability to apply this single combined transformation. | ||
@@ -290,0 +292,0 @@ ) |
| Metadata-Version: 2.1 | ||
| Name: targetran | ||
| Version: 0.11.9 | ||
| Version: 0.12.0 | ||
| Summary: Target transformation for data augmentation in objection detection | ||
@@ -195,2 +195,3 @@ Home-page: https://github.com/bhky/targetran | ||
| selected_probabilities=[0.5, 0.0, 0.3, 0.2, 0.0], # Must sum up to 1.0, if given. | ||
| keep_order=True, # If True, the selected steps must be performed in the given order. | ||
| probability=1.0 # Probability to apply this single combined transformation. | ||
@@ -302,2 +303,3 @@ ) | ||
| selected_probabilities=[0.5, 0.0, 0.3, 0.2, 0.0], # Must sum up to 1.0, if given. | ||
| keep_order=True, # If True, the selected steps must be performed in the given order. | ||
| probability=1.0 # Probability to apply this single combined transformation. | ||
@@ -304,0 +306,0 @@ ) |
@@ -1,3 +0,3 @@ | ||
| __version__ = "0.11.9" | ||
| __version__ = "0.12.0" | ||
| __author__ = "Bosco Yung" | ||
| __license__ = "MIT" |
@@ -16,4 +16,12 @@ """ | ||
| ) | ||
| from targetran.utils import Interpolation | ||
| _INTERPOLATION_DICT = { | ||
| Interpolation.NEAREST: cv2.INTER_NEAREST, # pylint: disable=no-member | ||
| Interpolation.BILINEAR: cv2.INTER_LINEAR, # pylint: disable=no-member | ||
| Interpolation.BICUBIC: cv2.INTER_CUBIC, # pylint: disable=no-member | ||
| Interpolation.AREA: cv2.INTER_AREA, # pylint: disable=no-member | ||
| } | ||
| def _np_convert(x: ArrayLike) -> NDFloatArray: | ||
@@ -58,3 +66,4 @@ if isinstance(x, np.ndarray): | ||
| image: NDFloatArray, | ||
| dest_size: Tuple[int, int] | ||
| dest_size: Tuple[int, int], | ||
| interpolation: Interpolation | ||
| ) -> NDFloatArray: | ||
@@ -67,3 +76,3 @@ """ | ||
| dsize=(dest_size[1], dest_size[0]), | ||
| interpolation=cv2.INTER_AREA # pylint: disable=no-member | ||
| interpolation=_INTERPOLATION_DICT[interpolation] | ||
| ) | ||
@@ -70,0 +79,0 @@ return resized_image |
@@ -9,4 +9,12 @@ """ | ||
| from targetran._typing import ArrayLike | ||
| from targetran.utils import Interpolation | ||
| _TF_INTERPOLATION_DICT = { | ||
| Interpolation.NEAREST: tf.image.ResizeMethod.NEAREST_NEIGHBOR, | ||
| Interpolation.BILINEAR: tf.image.ResizeMethod.BILINEAR, | ||
| Interpolation.BICUBIC: tf.image.ResizeMethod.BICUBIC, | ||
| Interpolation.AREA: tf.image.ResizeMethod.AREA, | ||
| } | ||
| def _tf_convert(x: ArrayLike) -> tf.Tensor: | ||
@@ -46,3 +54,4 @@ if isinstance(x, tf.Tensor): | ||
| image: tf.Tensor, | ||
| dest_size: Tuple[int, int] | ||
| dest_size: Tuple[int, int], | ||
| interpolation: Interpolation | ||
| ) -> tf.Tensor: | ||
@@ -53,3 +62,3 @@ """ | ||
| return tf.image.resize( | ||
| image, size=dest_size, method=tf.image.ResizeMethod.AREA | ||
| image, size=dest_size, method=_TF_INTERPOLATION_DICT[interpolation] | ||
| ) | ||
@@ -56,0 +65,0 @@ |
+20
-14
@@ -71,2 +71,3 @@ """ | ||
| interpolation: Interpolation, | ||
| fill_value: float, | ||
| d: _AffineDependency | ||
@@ -91,6 +92,12 @@ ) -> Tuple[T, T, T]: | ||
| # Pad image to provide a zero-value pixel frame for clipping use below. | ||
| # Pad image to provide a fill-value pixel frame for clipping use below. | ||
| fill_image = d.ones_like_fn(image) * fill_value | ||
| pad_offsets = d.convert_fn([1, 1, 1, 1]) | ||
| image = d.pad_image_fn(image, pad_offsets) | ||
| fill_image = d.pad_image_fn(fill_image, pad_offsets) | ||
| fill_image = (fill_image - fill_value) * -1.0 | ||
| image = image + fill_image | ||
| # References: | ||
@@ -174,3 +181,3 @@ # https://www.kaggle.com/cdeotte/rotation-augmentation-gpu-tpu-0-96 | ||
| else: | ||
| raise ValueError("Undefined interpolation option.") | ||
| raise ValueError("Unsupported interpolation option.") | ||
@@ -278,3 +285,2 @@ new_image = d.reshape_fn(values, (height, width, num_channels)) | ||
| labels: T, | ||
| interpolation: Interpolation, | ||
| d: _AffineDependency | ||
@@ -292,3 +298,3 @@ ) -> Tuple[T, T, T]: | ||
| image, bboxes, labels, image_dest_flip_lr_mat, bboxes_flip_lr_mat, | ||
| interpolation, d | ||
| Interpolation.NEAREST, 0.0, d # Dummy interpolation and fill_value. | ||
| ) | ||
@@ -317,3 +323,2 @@ | ||
| labels: T, | ||
| interpolation: Interpolation, | ||
| d: _AffineDependency | ||
@@ -331,3 +336,3 @@ ) -> Tuple[T, T, T]: | ||
| image, bboxes, labels, image_dest_flip_ud_mat, bboxes_flip_ud_mat, | ||
| interpolation, d | ||
| Interpolation.NEAREST, 0.0, d # Dummy interpolation and fill_value. | ||
| ) | ||
@@ -366,2 +371,3 @@ | ||
| interpolation: Interpolation, | ||
| fill_value: float, | ||
| d: _AffineDependency | ||
@@ -380,3 +386,3 @@ ) -> Tuple[T, T, T]: | ||
| image, bboxes, labels, image_dest_rot_mat, bboxes_rot_mat, | ||
| interpolation, d | ||
| interpolation, fill_value, d | ||
| ) | ||
@@ -414,2 +420,3 @@ | ||
| interpolation: Interpolation, | ||
| fill_value: float, | ||
| d: _AffineDependency | ||
@@ -428,3 +435,3 @@ ) -> Tuple[T, T, T]: | ||
| image, bboxes, labels, image_dest_shear_mat, bboxes_shear_mat, | ||
| interpolation, d | ||
| interpolation, fill_value, d | ||
| ) | ||
@@ -458,2 +465,3 @@ | ||
| interpolation: Interpolation, | ||
| fill_value: float, | ||
| d: _AffineDependency | ||
@@ -473,3 +481,3 @@ ) -> Tuple[T, T, T]: | ||
| image, bboxes, labels, image_dest_translate_mat, bboxes_translate_mat, | ||
| interpolation, d | ||
| interpolation, fill_value, d | ||
| ) | ||
@@ -603,6 +611,7 @@ | ||
| dest_size: Tuple[int, int], | ||
| interpolation: Interpolation, | ||
| convert_fn: Callable[..., T], | ||
| shape_fn: Callable[[T], Sequence[int]], | ||
| reshape_fn: Callable[[T, Sequence[int]], T], | ||
| resize_image_fn: Callable[[T, Tuple[int, int]], T], | ||
| resize_image_fn: Callable[[T, Tuple[int, int], Interpolation], T], | ||
| concat_fn: Callable[[List[T], int], T], | ||
@@ -619,8 +628,5 @@ ) -> Tuple[T, T, T]: | ||
| ) | ||
| image_shape = shape_fn(image) | ||
| if image_shape[0] == dest_size[0] and image_shape[1] == dest_size[1]: | ||
| return image, bboxes, labels | ||
| image = resize_image_fn(image, dest_size) | ||
| image = resize_image_fn(image, dest_size, interpolation) | ||
@@ -627,0 +633,0 @@ w = convert_fn(dest_size[1] / image_shape[1]) |
+64
-39
| """ | ||
| API for NumPy usage. | ||
| """ | ||
| import functools | ||
| from typing import Any, Callable, List, Optional, Sequence, Tuple | ||
@@ -66,7 +65,8 @@ | ||
| bboxes_tran_mat: NDFloatArray, | ||
| interpolation: Interpolation | ||
| interpolation: Interpolation, | ||
| fill_value: float | ||
| ) -> Tuple[NDFloatArray, NDFloatArray, NDFloatArray]: | ||
| return _affine_transform( | ||
| image, bboxes, labels, image_dest_tran_mat, bboxes_tran_mat, | ||
| interpolation, _np_get_affine_dependency() | ||
| interpolation, fill_value, _np_get_affine_dependency() | ||
| ) | ||
@@ -81,4 +81,3 @@ | ||
| return _flip_left_right( | ||
| image, bboxes, labels, | ||
| Interpolation.NEAREST, _np_get_affine_dependency() | ||
| image, bboxes, labels, _np_get_affine_dependency() | ||
| ) | ||
@@ -93,4 +92,3 @@ | ||
| return _flip_up_down( | ||
| image, bboxes, labels, | ||
| Interpolation.NEAREST, _np_get_affine_dependency() | ||
| image, bboxes, labels, _np_get_affine_dependency() | ||
| ) | ||
@@ -104,7 +102,8 @@ | ||
| angle_deg: float, | ||
| interpolation: Interpolation = Interpolation.BILINEAR | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0 | ||
| ) -> Tuple[NDFloatArray, NDFloatArray, NDFloatArray]: | ||
| return _rotate( | ||
| image, bboxes, labels, _np_convert(angle_deg), np.cos, np.sin, | ||
| interpolation, _np_get_affine_dependency() | ||
| interpolation, fill_value, _np_get_affine_dependency() | ||
| ) | ||
@@ -119,2 +118,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| _check_input: bool = True | ||
@@ -126,3 +126,3 @@ ) -> Tuple[NDFloatArray, NDFloatArray, NDFloatArray]: | ||
| image, bboxes, labels, _np_convert(angle_deg), np.tan, | ||
| interpolation, _np_get_affine_dependency() | ||
| interpolation, fill_value, _np_get_affine_dependency() | ||
| ) | ||
@@ -138,2 +138,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| _check_input: bool = True | ||
@@ -146,3 +147,3 @@ ) -> Tuple[NDFloatArray, NDFloatArray, NDFloatArray]: | ||
| _np_convert(translate_height), _np_convert(translate_width), | ||
| interpolation, _np_get_affine_dependency() | ||
| interpolation, fill_value, _np_get_affine_dependency() | ||
| ) | ||
@@ -189,6 +190,7 @@ | ||
| labels: NDFloatArray, | ||
| dest_size: Tuple[int, int] | ||
| dest_size: Tuple[int, int], | ||
| interpolation: Interpolation = Interpolation.BILINEAR | ||
| ) -> Tuple[NDFloatArray, NDFloatArray, NDFloatArray]: | ||
| return _resize( | ||
| image, bboxes, labels, dest_size, | ||
| image, bboxes, labels, dest_size, interpolation, | ||
| _np_convert, np.shape, np.reshape, _np_resize_image, np.concatenate | ||
@@ -210,3 +212,4 @@ ) | ||
| self.probability = probability | ||
| self._rng = np.random.default_rng(seed=seed) | ||
| self.seed = seed | ||
| self._rng = np.random.default_rng(seed=self.seed) | ||
| self.name = name | ||
@@ -250,3 +253,5 @@ self.is_affine = is_affine | ||
| selected_probabilities: Optional[List[float]] = None, | ||
| keep_order: bool = False, | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 1.0, | ||
@@ -273,6 +278,5 @@ seed: Optional[int] = None | ||
| self._selected_probabilities = selected_probabilities | ||
| self._keep_order = keep_order | ||
| self._interpolation = interpolation | ||
| self._identity_mat = np.expand_dims(np.array([ | ||
| [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] | ||
| ]), axis=0) | ||
| self._fill_value = fill_value | ||
@@ -289,3 +293,3 @@ def _get_mats( | ||
| if self._num_selected_transforms: | ||
| if self._num_selected_transforms is not None: | ||
| indices = self._rng.choice( | ||
@@ -295,21 +299,31 @@ len(self._transforms), | ||
| replace=False, p=self._selected_probabilities | ||
| ).tolist() | ||
| ) | ||
| else: | ||
| conditions = rand_fn() < probs | ||
| indices = np.arange(len(probs), dtype=np.int32)[conditions] | ||
| if len(indices) > 1: | ||
| if self._keep_order: | ||
| indices.sort() | ||
| else: | ||
| self._rng.shuffle(indices) | ||
| indices = indices.tolist() | ||
| image_dest_tran_mats = np.take(image_dest_tran_mats, indices, 0) | ||
| bboxes_tran_mats = np.take(bboxes_tran_mats, indices, 0) | ||
| image_dest_tran_mat = np.linalg.multi_dot(image_dest_tran_mats) | ||
| # Note the reversed order for the bboxes tran matrices. | ||
| bboxes_tran_mat = np.linalg.multi_dot(bboxes_tran_mats[::-1]) | ||
| elif len(indices) == 1: | ||
| image_dest_tran_mat = image_dest_tran_mats[0] | ||
| bboxes_tran_mat = bboxes_tran_mats[0] | ||
| else: | ||
| conditions = np.reshape(rand_fn() < probs, (len(probs), 1, 1)) | ||
| image_dest_tran_mats = np.where( # type: ignore | ||
| conditions, image_dest_tran_mats, self._identity_mat | ||
| ) | ||
| bboxes_tran_mats = np.where( # type: ignore | ||
| conditions, bboxes_tran_mats, self._identity_mat | ||
| ) | ||
| # This happens when conditions are all False, or | ||
| # num_selected_transforms is 0. | ||
| assert len(indices) == 0 | ||
| image_dest_tran_mat = np.identity(3) | ||
| bboxes_tran_mat = np.identity(3) | ||
| image_dest_tran_mat = functools.reduce( | ||
| np.matmul, image_dest_tran_mats | ||
| ) | ||
| # Note the reversed order for the bboxes tran matrices. | ||
| bboxes_tran_mat = functools.reduce( | ||
| np.matmul, bboxes_tran_mats[::-1] | ||
| ) | ||
| return image_dest_tran_mat, bboxes_tran_mat | ||
@@ -330,3 +344,3 @@ | ||
| image, bboxes, labels, image_dest_tran_mat, bboxes_tran_mat, | ||
| self._interpolation | ||
| self._interpolation, self._fill_value | ||
| ) | ||
@@ -399,2 +413,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 0.9, | ||
@@ -407,2 +422,3 @@ seed: Optional[int] = None | ||
| self.interpolation = interpolation | ||
| self.fill_value = fill_value | ||
@@ -437,3 +453,3 @@ def _get_angle_deg( | ||
| image, bboxes, labels, self._get_angle_deg(self._rand_fn), | ||
| self.interpolation | ||
| self.interpolation, self.fill_value | ||
| ) | ||
@@ -448,2 +464,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 0.9, | ||
@@ -456,2 +473,3 @@ seed: Optional[int] = None | ||
| self.interpolation = interpolation | ||
| self.fill_value = fill_value | ||
@@ -484,3 +502,3 @@ def _get_angle_deg( | ||
| image, bboxes, labels, self._get_angle_deg(self._rand_fn), | ||
| self.interpolation, False | ||
| self.interpolation, self.fill_value, False | ||
| ) | ||
@@ -496,2 +514,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 0.9, | ||
@@ -512,2 +531,3 @@ seed: Optional[int] = None | ||
| self.interpolation = interpolation | ||
| self.fill_value = fill_value | ||
@@ -555,3 +575,3 @@ def _get_translate_height_and_width( | ||
| image, bboxes, labels, translate_height, translate_width, | ||
| self.interpolation, False | ||
| self.interpolation, self.fill_value, False | ||
| ) | ||
@@ -603,4 +623,9 @@ | ||
| def __init__(self, dest_size: Tuple[int, int]) -> None: | ||
| def __init__( | ||
| self, | ||
| dest_size: Tuple[int, int], | ||
| interpolation: Interpolation = Interpolation.BILINEAR | ||
| ) -> None: | ||
| self.dest_size = dest_size | ||
| self.interpolation = interpolation | ||
| self.name = "Resize" | ||
@@ -615,2 +640,2 @@ self.is_affine = False | ||
| ) -> Tuple[NDFloatArray, NDFloatArray, NDFloatArray]: | ||
| return resize(image, bboxes, labels, self.dest_size) | ||
| return resize(image, bboxes, labels, self.dest_size, self.interpolation) |
+69
-44
| """ | ||
| API for TensorFlow usage. | ||
| """ | ||
| import functools | ||
| import itertools | ||
@@ -116,7 +115,8 @@ from typing import Any, Callable, List, Optional, Sequence, Tuple | ||
| bboxes_tran_mat: tf.Tensor, | ||
| interpolation: Interpolation | ||
| interpolation: Interpolation, | ||
| fill_value: float | ||
| ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]: | ||
| return _affine_transform( | ||
| image, bboxes, labels, image_dest_tran_mat, bboxes_tran_mat, | ||
| interpolation, _tf_get_affine_dependency() | ||
| interpolation, fill_value, _tf_get_affine_dependency() | ||
| ) | ||
@@ -131,4 +131,3 @@ | ||
| return _flip_left_right( | ||
| image, bboxes, labels, | ||
| Interpolation.NEAREST, _tf_get_affine_dependency() | ||
| image, bboxes, labels, _tf_get_affine_dependency() | ||
| ) | ||
@@ -143,4 +142,3 @@ | ||
| return _flip_up_down( | ||
| image, bboxes, labels, | ||
| Interpolation.NEAREST, _tf_get_affine_dependency() | ||
| image, bboxes, labels, _tf_get_affine_dependency() | ||
| ) | ||
@@ -154,7 +152,8 @@ | ||
| angle_deg: float, | ||
| interpolation: Interpolation = Interpolation.BILINEAR | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0 | ||
| ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]: | ||
| return _rotate( | ||
| image, bboxes, labels, _tf_convert(angle_deg), tf.cos, tf.sin, | ||
| interpolation, _tf_get_affine_dependency() | ||
| interpolation, fill_value, _tf_get_affine_dependency() | ||
| ) | ||
@@ -169,2 +168,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| _check_input: bool = True | ||
@@ -176,3 +176,3 @@ ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]: | ||
| image, bboxes, labels, _tf_convert(angle_deg), tf.tan, | ||
| interpolation, _tf_get_affine_dependency() | ||
| interpolation, fill_value, _tf_get_affine_dependency() | ||
| ) | ||
@@ -188,2 +188,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| _check_input: bool = True | ||
@@ -198,3 +199,3 @@ ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]: | ||
| _tf_convert(translate_height), _tf_convert(translate_width), | ||
| interpolation, _tf_get_affine_dependency() | ||
| interpolation, fill_value, _tf_get_affine_dependency() | ||
| ) | ||
@@ -241,6 +242,7 @@ | ||
| labels: tf.Tensor, | ||
| dest_size: Tuple[int, int] | ||
| dest_size: Tuple[int, int], | ||
| interpolation: Interpolation = Interpolation.BILINEAR | ||
| ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]: | ||
| return _resize( | ||
| image, bboxes, labels, dest_size, | ||
| image, bboxes, labels, dest_size, interpolation, | ||
| _tf_convert, tf.shape, tf.reshape, _tf_resize_image, tf.concat | ||
@@ -262,5 +264,4 @@ ) | ||
| self.probability = probability | ||
| self._rng = tf.random.Generator.from_seed( | ||
| seed if seed is not None else np.random.randint(1e6) # type: ignore | ||
| ) | ||
| self.seed = seed if seed is not None else np.random.randint(1e6) # type: ignore | ||
| self._rng = tf.random.Generator.from_seed(self.seed) | ||
| self.name = name | ||
@@ -316,3 +317,3 @@ self.is_affine = is_affine | ||
| )) | ||
| _, indices = tf.nn.top_k(logits + z, num_selected_indices) | ||
| _, indices = tf.math.top_k(logits + z, num_selected_indices, sorted=False) | ||
| return indices | ||
@@ -328,3 +329,5 @@ | ||
| selected_probabilities: Optional[List[float]] = None, | ||
| keep_order: bool = False, | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 1.0, | ||
@@ -351,6 +354,5 @@ seed: Optional[int] = None | ||
| self._selected_probabilities = selected_probabilities | ||
| self._keep_order = keep_order | ||
| self._interpolation = interpolation | ||
| self._identity_mat = tf.expand_dims(tf.constant([ | ||
| [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] | ||
| ]), axis=0) | ||
| self._fill_value = fill_value | ||
@@ -367,3 +369,6 @@ def _get_mats( | ||
| if self._num_selected_transforms: | ||
| if self._num_selected_transforms is not None: | ||
| if self._num_selected_transforms == 0: | ||
| return tf.eye(3), tf.eye(3) | ||
| indices = _get_random_indices( | ||
@@ -375,24 +380,33 @@ self._rng, | ||
| ) | ||
| image_dest_tran_mats = tf.gather( # pylint: disable=no-value-for-parameter | ||
| image_dest_tran_mats, indices | ||
| ) | ||
| bboxes_tran_mats = tf.gather( # pylint: disable=no-value-for-parameter | ||
| bboxes_tran_mats, indices | ||
| ) | ||
| else: | ||
| conditions = tf.reshape(rand_fn() < probs, (len(probs), 1, 1)) | ||
| image_dest_tran_mats = tf.where( | ||
| conditions, image_dest_tran_mats, self._identity_mat | ||
| # It looks like in graph mode we cannot check if a tensor is empty | ||
| # and then do short circuit. Therefore, to prevent empty indices | ||
| # which tf.gather could not handle, an identity matrix is appended. | ||
| image_dest_tran_mats += (tf.eye(3),) | ||
| bboxes_tran_mats += (tf.eye(3),) | ||
| probs += (1.0,) | ||
| conditions = rand_fn() < probs | ||
| indices = tf.boolean_mask( | ||
| tf.range(len(probs), dtype=tf.int32), conditions | ||
| ) | ||
| bboxes_tran_mats = tf.where( | ||
| conditions, bboxes_tran_mats, self._identity_mat | ||
| ) | ||
| image_dest_tran_mat = functools.reduce( | ||
| tf.matmul, tf.unstack(image_dest_tran_mats) | ||
| if self._keep_order: | ||
| indices = tf.sort(indices) | ||
| else: | ||
| indices = tf.random.shuffle(indices, seed=self.seed) | ||
| image_dest_tran_mats = tf.gather( # pylint: disable=no-value-for-parameter | ||
| image_dest_tran_mats, indices | ||
| ) | ||
| bboxes_tran_mats = tf.gather( # pylint: disable=no-value-for-parameter | ||
| bboxes_tran_mats, indices | ||
| ) | ||
| def matmul(a: tf.Tensor, b: tf.Tensor) -> tf.Tensor: | ||
| return tf.matmul(a, b) | ||
| image_dest_tran_mat = tf.scan(matmul, image_dest_tran_mats)[-1] | ||
| # Note the reversed order for the bboxes tran matrices. | ||
| bboxes_tran_mat = functools.reduce( | ||
| tf.matmul, tf.unstack(bboxes_tran_mats)[::-1] | ||
| ) | ||
| bboxes_tran_mat = tf.scan(matmul, bboxes_tran_mats[::-1])[-1] | ||
| return image_dest_tran_mat, bboxes_tran_mat | ||
@@ -413,3 +427,3 @@ | ||
| image, bboxes, labels, image_dest_tran_mat, bboxes_tran_mat, | ||
| self._interpolation | ||
| self._interpolation, self._fill_value | ||
| ) | ||
@@ -482,2 +496,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 0.9, | ||
@@ -490,2 +505,3 @@ seed: Optional[int] = None | ||
| self.interpolation = interpolation | ||
| self.fill_value = fill_value | ||
@@ -515,3 +531,3 @@ def _get_angle_deg(self, rand_fn: Callable[..., tf.Tensor]) -> tf.Tensor: | ||
| image, bboxes, labels, self._get_angle_deg(self._rand_fn), | ||
| self.interpolation | ||
| self.interpolation, self.fill_value | ||
| ) | ||
@@ -526,2 +542,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 0.9, | ||
@@ -534,2 +551,3 @@ seed: Optional[int] = None | ||
| self.interpolation = interpolation | ||
| self.fill_value = fill_value | ||
@@ -559,3 +577,3 @@ def _get_angle_deg(self, rand_fn: Callable[..., tf.Tensor]) -> tf.Tensor: | ||
| image, bboxes, labels, self._get_angle_deg(self._rand_fn), | ||
| self.interpolation, False | ||
| self.interpolation, self.fill_value, False | ||
| ) | ||
@@ -571,2 +589,3 @@ | ||
| interpolation: Interpolation = Interpolation.BILINEAR, | ||
| fill_value: float = 0.0, | ||
| probability: float = 0.9, | ||
@@ -589,2 +608,3 @@ seed: Optional[int] = None | ||
| self.interpolation = interpolation | ||
| self.fill_value = fill_value | ||
@@ -628,3 +648,3 @@ def _get_translate_height_and_width( | ||
| image, bboxes, labels, translate_height, translate_width, | ||
| self.interpolation, False | ||
| self.interpolation, self.fill_value, False | ||
| ) | ||
@@ -676,4 +696,9 @@ | ||
| def __init__(self, dest_size: Tuple[int, int]) -> None: | ||
| def __init__( | ||
| self, | ||
| dest_size: Tuple[int, int], | ||
| interpolation: Interpolation = Interpolation.BILINEAR | ||
| ) -> None: | ||
| self.dest_size = dest_size | ||
| self.interpolation = interpolation | ||
| self.name = "TFResize" | ||
@@ -688,2 +713,2 @@ self.is_affine = False | ||
| ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]: | ||
| return tf_resize(image, bboxes, labels, self.dest_size) | ||
| return tf_resize(image, bboxes, labels, self.dest_size, self.interpolation) |
@@ -13,2 +13,4 @@ """ | ||
| BILINEAR = auto() | ||
| BICUBIC = auto() | ||
| AREA = auto() | ||
@@ -15,0 +17,0 @@ |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
117091
3.28%1966
3.36%