Skip to content

Instantly share code, notes, and snippets.

@nihui
Created August 29, 2019 10:00
Show Gist options
  • Save nihui/b9a9e65eca7a75a24d7a9e74a176ea0b to your computer and use it in GitHub Desktop.
Save nihui/b9a9e65eca7a75a24d7a9e74a176ea0b to your computer and use it in GitHub Desktop.
gluon random crop and resize on gpu
# 256x256
data = batch.data[0].as_in_context(ctx)
# random crop resize to 224x224
data_elems = nd.split(data, num_outputs=batch_size, axis=0)
for b in range(batch_size):
xy0 = random.randint(0, 32)
xy1 = random.randint(256-32, 256)
cropped = nd.slice(data_elems[b], begin=(None,None,xy0,xy0), end=(None,None,xy1,xy1))
cropped_resized = nd.contrib.BilinearResize2D(cropped, height=224, width=224)
data_elems[b] = cropped_resized
data = nd.concat(*data_elems, dim=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment