targetran
Advanced tools
+1
-1
| Metadata-Version: 2.1 | ||
| Name: targetran | ||
| Version: 0.11.7 | ||
| Version: 0.11.8 | ||
| Summary: Target transformation for data augmentation in objection detection | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/bhky/targetran |
| Metadata-Version: 2.1 | ||
| Name: targetran | ||
| Version: 0.11.7 | ||
| Version: 0.11.8 | ||
| Summary: Target transformation for data augmentation in objection detection | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/bhky/targetran |
@@ -1,3 +0,3 @@ | ||
| __version__ = "0.11.7" | ||
| __version__ = "0.11.8" | ||
| __author__ = "Bosco Yung" | ||
| __license__ = "MIT" |
+27
-25
@@ -73,2 +73,6 @@ """ | ||
| """ | ||
| Original transformation is done w.r.t. the origin (top-left pixel). | ||
| Hence, additional translation is also performed to make the transformation | ||
| w.r.t. the image centre. | ||
| image: [h, w, c] | ||
@@ -84,3 +88,2 @@ bboxes: [[top_left_x, top_left_y, width, height], ...] | ||
| height, width = int(image_shape[0]), int(image_shape[1]) | ||
| h_mod, w_mod = height % 2, width % 2 | ||
| num_channels = int(image_shape[2]) | ||
@@ -95,9 +98,9 @@ | ||
| # Destination indices. Note that (-foo // 2) != -(foo // 2). | ||
| # Destination indices. | ||
| row_idxes = d.repeat_fn( # Along y-axis, from top to bottom. | ||
| d.range_fn(-(height // 2) + 1 - h_mod, height // 2 + 1, 1), | ||
| d.range_fn(0, height, 1), | ||
| d.round_to_int_fn(d.convert_fn([width])) | ||
| ) | ||
| col_idxes = d.tile_fn( # Along x-axis, from left to right. | ||
| d.range_fn(-(width // 2) + 1 - w_mod, width // 2 + 1, 1), | ||
| d.range_fn(0, width, 1), | ||
| d.round_to_int_fn(d.convert_fn([height])) | ||
@@ -110,23 +113,29 @@ ) | ||
| # Transform destination indices, with clipping. Note that these are floats. | ||
| # Transform destination indices, align centre of the idx matrix to | ||
| # that of the image, and clipping. Note that these are floats. | ||
| new_image_dest_idxes = d.matmul_fn( | ||
| image_dest_tran_mat, d.convert_fn(image_dest_idxes) | ||
| ) | ||
| image_cen = d.convert_fn([ | ||
| [d.convert_fn(width - 1) / 2.0], | ||
| [d.convert_fn(height - 1) / 2.0], | ||
| [0.0] | ||
| ]) | ||
| new_image_dest_idxes -= \ | ||
| d.matmul_fn(image_dest_tran_mat, image_cen) - image_cen | ||
| clipped_new_image_dest_idxes = d.clip_fn( | ||
| new_image_dest_idxes[:2], | ||
| # Note the extra idx for the padded frame. | ||
| d.convert_fn([ | ||
| [-(width // 2) - w_mod], [-(height // 2) - h_mod] | ||
| ]), | ||
| d.convert_fn([ | ||
| [width // 2 + 1], [height // 2 + 1] | ||
| ]) | ||
| d.convert_fn([[-1], [-1]]), | ||
| d.convert_fn([[width], [height]]) | ||
| ) | ||
| # Assigning original pixel values to new positions. | ||
| # Note the 1-pixel shift for the padded frame. | ||
| image_orig_idxes = d.concat_fn([ | ||
| # Rows. | ||
| clipped_new_image_dest_idxes[1:] + d.convert_fn(height // 2 + h_mod), | ||
| clipped_new_image_dest_idxes[1:] + d.convert_fn(1), | ||
| # Columns. | ||
| clipped_new_image_dest_idxes[:1] + d.convert_fn(width // 2 + w_mod) | ||
| clipped_new_image_dest_idxes[:1] + d.convert_fn(1) | ||
| ], 0) | ||
@@ -180,14 +189,6 @@ | ||
| xs = d.concat_fn( | ||
| [top_left_xs - d.convert_fn(width // 2 - 1 + w_mod), | ||
| top_right_xs - d.convert_fn(width // 2 - 1 + w_mod), | ||
| bottom_left_xs - d.convert_fn(width // 2 - 1 + w_mod), | ||
| bottom_right_xs - d.convert_fn(width // 2 - 1 + w_mod)], | ||
| 1 | ||
| [top_left_xs, top_right_xs, bottom_left_xs, bottom_right_xs], 1 | ||
| ) | ||
| ys = d.concat_fn( | ||
| [top_left_ys - d.convert_fn(height // 2 - 1 + h_mod), | ||
| top_right_ys - d.convert_fn(height // 2 - 1 + h_mod), | ||
| bottom_left_ys - d.convert_fn(height // 2 - 1 + h_mod), | ||
| bottom_right_ys - d.convert_fn(height // 2 - 1 + h_mod)], | ||
| 1 | ||
| [top_left_ys, top_right_ys, bottom_left_ys, bottom_right_ys], 1 | ||
| ) | ||
@@ -199,2 +200,3 @@ bboxes_idxes = d.stack_fn( # Shape: [num_bboxes, 3, 4]. | ||
| tran_bboxes_idxes = d.matmul_fn(bboxes_tran_mat, bboxes_idxes) | ||
| tran_bboxes_idxes -= d.matmul_fn(bboxes_tran_mat, image_cen) - image_cen | ||
@@ -221,4 +223,4 @@ # New bboxes, defined as the rectangle enclosing the transformed bboxes. | ||
| new_xs = tran_bboxes[:, :1] + width // 2 + w_mod - 1 | ||
| new_ys = tran_bboxes[:, 1:2] + height // 2 + h_mod - 1 | ||
| new_xs = tran_bboxes[:, :1] | ||
| new_ys = tran_bboxes[:, 1:2] | ||
@@ -225,0 +227,0 @@ # Filter new bboxes values. |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
113230
-0.11%