Guest User

Untitled

a guest
Jun 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. def sample_swap(shape):
  2. b, c, h, w = shape
  3. left = np.arange(0, w//2)
  4. right = np.arange(w//2, w)
  5. flip = np.random.uniform(size=(b, 1)) > .5
  6. b = np.arange(b)[:, None, None, None]
  7. c = np.arange(c)[None, :, None, None]
  8. h = np.arange(h)[None, None, :, None]
  9. w = np.concatenate([left+flip*(w//2), right-flip*(w//2)], -1)
  10. w = w[:, None, None, :]
  11. return np.broadcast_arrays(b, c, h, w)
Add Comment
Please, Sign In to add comment