MCPcopy Create free account
hub / github.com/KerenLab/CellSighter / ShiftAugmentation

Class ShiftAugmentation

data/shift_augmentation.py:6–25  ·  view source on GitHub ↗

Augmentation that shift each marker channel a few pixels in random direction

Source from the content-addressed store, hash-verified

4
5
6class ShiftAugmentation(torch.nn.Module):
7 """
8 Augmentation that shift each marker channel a few pixels in random direction
9 """
10 def __init__(self, n_size, shift_max=0):
11 super(ShiftAugmentation, self).__init__()
12 self.shift_max = shift_max
13 self.n_size = n_size
14 p = 0.3
15
16 self.chanel_shifter = Lambda(lambda x:
17 RandomCrop(size=n_size)(
18 CenterCrop(size=n_size + (self.shift_max if np.random.random() < p else 0))(x)))
19
20 def forward(self, x):
21 # X is shaped: (C, H, W)
22 aug_x = torch.zeros((x.shape[0], self.n_size, self.n_size))
23 for i in range(x.shape[0]):
24 aug_x[i, :, :] = self.chanel_shifter(x[[i], :, :])[0,:,:]
25 return aug_x

Callers 1

transform.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected