MCPcopy Create free account
hub / github.com/Intelligent-Computing-Lab-Panda/NDA_SNN / cutmix_data

Function cutmix_data

functions/data_loaders.py:185–197  ·  view source on GitHub ↗
(input, target, alpha=1.0)

Source from the content-addressed store, hash-verified

183
184
185def cutmix_data(input, target, alpha=1.0):
186 lam = np.random.beta(alpha, alpha)
187 rand_index = torch.randperm(input.size()[0]).cuda()
188
189 target_a = target
190 target_b = target[rand_index]
191
192 # generate mixed sample
193 bbx1, bby1, bbx2, bby2 = rand_bbox(input.size(), lam)
194 input[:, :, :, bbx1:bbx2, bby1:bby2] = input[rand_index, :, :, bbx1:bbx2, bby1:bby2]
195 # adjust lambda to exactly match pixel ratio
196 lam = 1 - ((bbx2 - bbx1) * (bby2 - bby1) / (input.size()[-1] * input.size()[-2]))
197 return input, target_a, target_b, lam
198
199
200if __name__ == '__main__':

Callers

nothing calls this directly

Calls 1

rand_bboxFunction · 0.85

Tested by

no test coverage detected