| 16 | |
| 17 | |
| 18 | def get_patch(input, target, patch_size, scale = 1, ix=-1, iy=-1): |
| 19 | # if(len(input.shape)<3): |
| 20 | # input = np.expand_dims(input, 2).repeat(3, axis = 2) |
| 21 | # ih, iw, channels = input.shape |
| 22 | # if(ih<384): |
| 23 | # input = np.pad(input, ((0,384-ih)), 'edge') |
| 24 | # elif(iw<384): |
| 25 | # input = np.pad(input, ((1,384-iw)), 'edge') |
| 26 | ih, iw, channels = input.shape |
| 27 | |
| 28 | # (th, tw) = (scale * ih, scale * iw) |
| 29 | |
| 30 | patch_mult = scale # if len(scale) > 1 else 1 |
| 31 | tp = patch_mult * patch_size |
| 32 | ip = tp // scale |
| 33 | |
| 34 | if ix == -1: |
| 35 | ix = random.randrange(0, ih - ip + 1) |
| 36 | if iy == -1: |
| 37 | iy = random.randrange(0, iw - ip + 1) |
| 38 | |
| 39 | # (tx, ty) = (scale * ix, scale * iy) |
| 40 | |
| 41 | |
| 42 | input = input[ix:ix + ip, iy:iy + ip, :] # [:, ty:ty + tp, tx:tx + tp] |
| 43 | target = target[ix:ix + ip, iy:iy + ip, :] # [:, iy:iy + ip, ix:ix + ip] |
| 44 | |
| 45 | |
| 46 | return input, target |
| 47 | |
| 48 | |
| 49 | def augment(inputs, target, hflip, rot): |