Last active
June 22, 2018 11:01
-
-
Save ferrine/45f764511c327ca76da707cce9284028 to your computer and use it in GitHub Desktop.
sample swap for image (batch, cannel, height, width*2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample_swap(shape): | |
b, c, h, w = shape | |
left = np.arange(0, w//2) | |
right = np.arange(w//2, w) | |
flip = np.random.uniform(size=(b, 1)) > .5 | |
b = np.arange(b)[:, None, None, None] | |
c = np.arange(c)[None, :, None, None] | |
h = np.arange(h)[None, None, :, None] | |
w = np.concatenate([left+flip*(w//2), right-flip*(w//2)], -1) | |
w = w[:, None, None, :] | |
return np.broadcast_arrays(b, c, h, w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment