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

RandomTranslate does not use fill parameter #249

Closed
ed1d1a8d opened this issue Aug 19, 2022 · 1 comment
Closed

RandomTranslate does not use fill parameter #249

ed1d1a8d opened this issue Aug 19, 2022 · 1 comment

Comments

@ed1d1a8d
Copy link

ed1d1a8d commented Aug 19, 2022

It seems RandomTranslate is broken in the sense that it does not make use of the fill parameter?

class RandomTranslate(Operation):
"""Translate each image randomly in vertical and horizontal directions
up to specified number of pixels.
Parameters
----------
padding : int
Max number of pixels to translate in any direction.
fill : tuple
An RGB color ((0, 0, 0) by default) to fill the area outside the shifted image.
"""
def __init__(self, padding: int, fill: Tuple[int, int, int] = (0, 0, 0)):
super().__init__()
self.padding = padding
self.fill = np.array(fill)
def generate_code(self) -> Callable:
my_range = Compiler.get_iterator()
pad = self.padding
def translate(images, dst):
n, h, w, _ = images.shape
# y_coords = randint(low=0, high=2 * pad + 1, size=(n,))
# x_coords = randint(low=0, high=2 * pad + 1, size=(n,))
# dst = fill
dst[:, pad:pad+h, pad:pad+w] = images
for i in my_range(n):
y_coord = randint(low=0, high=2 * pad + 1)
x_coord = randint(low=0, high=2 * pad + 1)
# images[i] = dst[i, y_coords[i]:y_coords[i]+h, x_coords[i]:x_coords[i]+w]
images[i] = dst[i, y_coord:y_coord+h, x_coord:x_coord+w]
return images
translate.is_parallel = True
return translate
def declare_state_and_memory(self, previous_state: State) -> Tuple[State, Optional[AllocationQuery]]:
h, w, c = previous_state.shape
return (replace(previous_state, jit_mode=True), \
AllocationQuery((h + 2 * self.padding, w + 2 * self.padding, c), previous_state.dtype))

Am I misreading the implementation here?

@andrewilyas
Copy link
Contributor

I think this is a duplicate of #175 and fixed in #184 ! Not sure why that isn't merged in yet, but I'll follow up on the pull request directly and close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants