Better design for RandomSizedBBoxSafeCrop without implicit resizing
See original GitHub issueThis is current definition of RandomSizedBBoxSafeCrop
class, which is on the transforms.py
class RandomSizedBBoxSafeCrop(DualTransform):
"""Crop a random part of the input and rescale it to some size without loss of bboxes.
Args:
height (int): height after crop and resize.
width (int): width after crop and resize.
erosion_rate (float): erosion rate applied on input image height before crop.
interpolation (OpenCV flag): flag that is used to specify the interpolation algorithm. Should be one of:
cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4.
Default: cv2.INTER_LINEAR.
p (float): probability of applying the transform. Default: 1.
Targets:
image, mask, bboxes
Image types:
uint8, float32
"""
def __init__(self, height, width, erosion_rate=0.0, interpolation=cv2.INTER_LINEAR, always_apply=False, p=1.0):
super(RandomSizedBBoxSafeCrop, self).__init__(always_apply, p)
self.height = height
self.width = width
self.interpolation = interpolation
self.erosion_rate = erosion_rate
def apply(self, img, crop_height=0, crop_width=0, h_start=0, w_start=0, interpolation=cv2.INTER_LINEAR, **params):
crop = F.random_crop(img, crop_height, crop_width, h_start, w_start)
return F.resize(crop, self.height, self.width, interpolation)
And this is my customization on the same class, without implicit resizing.
class RandomSizedBBoxSafeCrop(DualTransform):
"""Crop a random part of the input and rescale it to some size without loss of bboxes.
Args:
erosion_rate (float): erosion rate applied on input image height before crop.
p (float): probability of applying the transform. Default: 1.
Targets:
image, mask, bboxes
Image types:
uint8, float32
"""
def __init__(self, erosion_rate=0.0, always_apply=False, p=1.0):
super(RandomSizedBBoxSafeCrop, self).__init__(always_apply, p)
self.erosion_rate = erosion_rate
def apply(self, img, crop_height=0, crop_width=0, h_start=0, w_start=0, **params):
return F.random_crop(img, crop_height, crop_width, h_start, w_start)
I think the latter is better design, since it has simpler code and fits into more general use cases. If the resizing feature is really need for someone, it can be done explicitly by composing this with Resize.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Crop transforms (augmentations.crops.transforms)
Crop a random part of the input without loss of bboxes. Parameters: ... Note: This transformation automatically resizes images back to their original...
Read more >Minimal, Clean Examples Of Machine Learning Algorithms ... - Morioh
A collection of minimal and clean implementations of machine learning algorithms. Why? This project is targeting people who want to learn internals of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also we can set
height
andwidth
toNone
by default . And if one of them isNone
do not use resizeImplemented in #579