Chromatic augmentation: https://github.com/lmb-freiburg/flownet2/blob/master/src/caffe/layers/data_augmentation_layer.cu
| 399 | |
| 400 | |
| 401 | class ChromaticAug(object): |
| 402 | """ |
| 403 | Chromatic augmentation: https://github.com/lmb-freiburg/flownet2/blob/master/src/caffe/layers/data_augmentation_layer.cu |
| 404 | """ |
| 405 | def __init__(self, noise = 0.06, |
| 406 | gamma = 0.02, |
| 407 | brightness = 0.02, |
| 408 | contrast = 0.02, |
| 409 | color = 0.02, |
| 410 | schedule_coeff=1): |
| 411 | |
| 412 | self.noise = np.random.uniform(0,noise) |
| 413 | self.gamma = np.exp(np.random.normal(0, gamma*schedule_coeff)) |
| 414 | self.brightness = np.random.normal(0, brightness*schedule_coeff) |
| 415 | self.contrast = np.exp(np.random.normal(0, contrast*schedule_coeff)) |
| 416 | self.color = np.exp(np.random.normal(0, color*schedule_coeff,3)) |
| 417 | |
| 418 | def __call__(self, inputs, target): |
| 419 | inputs[1] = self.chrom_aug(inputs[1]) |
| 420 | # noise |
| 421 | inputs[0]+=np.random.normal(0, self.noise, inputs[0].shape) |
| 422 | inputs[1]+=np.random.normal(0, self.noise, inputs[0].shape) |
| 423 | return inputs,target |
| 424 | |
| 425 | def chrom_aug(self, rgb): |
| 426 | # color change |
| 427 | mean_in = rgb.sum(-1) |
| 428 | rgb = rgb*self.color[np.newaxis,np.newaxis] |
| 429 | brightness_coeff = mean_in / (rgb.sum(-1)+0.01) |
| 430 | rgb = np.clip(rgb*brightness_coeff[:,:,np.newaxis],0,1) |
| 431 | # gamma |
| 432 | rgb = np.power(rgb,self.gamma) |
| 433 | # brightness |
| 434 | rgb += self.brightness |
| 435 | # contrast |
| 436 | rgb = 0.5 + ( rgb-0.5)*self.contrast |
| 437 | rgb = np.clip(rgb, 0, 1) |
| 438 | return |
nothing calls this directly
no outgoing calls
no test coverage detected