@@ -140,7 +140,6 @@ def mixup(batch_size, aug_params, images, labels):
140140 aug_params: Dict of data augmentation hyper parameters.
141141 images: A batch of images of shape [batch_size, ...]
142142 labels: A batch of labels of shape [batch_size, num_classes]
143-
144143 Returns:
145144 A tuple of (images, labels) with the same dimensions as the input with
146145 Mixup regularization applied.
@@ -192,15 +191,16 @@ def mixup(batch_size, aug_params, images, labels):
192191 labels = tf .reshape (
193192 tf .tile (labels , [1 , aug_count + 1 ]), [batch_size , aug_count + 1 , - 1 ])
194193 labels_mix = (
195- labels * mix_weight +
196- tf . gather ( labels , mixup_index ) * (1. - mix_weight ))
194+ labels * mix_weight + tf . gather ( labels , mixup_index ) *
195+ (1. - mix_weight ))
197196 labels_mix = tf .reshape (
198197 tf .transpose (labels_mix , [1 , 0 , 2 ]), [batch_size * (aug_count + 1 ), - 1 ])
199198 else :
200199 labels_mix = (
201- labels * mix_weight +
202- tf .gather (labels , mixup_index ) * (1. - mix_weight ))
203- return images_mix , labels_mix
200+ labels * mix_weight + tf .gather (labels , mixup_index ) *
201+ (1. - mix_weight ))
202+
203+ return images_mix , labels_mix
204204
205205
206206def adaptive_mixup (batch_size , aug_params , images , labels ):
@@ -215,7 +215,6 @@ def adaptive_mixup(batch_size, aug_params, images, labels):
215215 aug_params: Dict of data augmentation hyper parameters.
216216 images: A batch of images of shape [batch_size, ...]
217217 labels: A batch of labels of shape [batch_size, num_classes]
218-
219218 Returns:
220219 A tuple of (images, labels) with the same dimensions as the input with
221220 Mixup regularization applied.
@@ -229,8 +228,8 @@ def adaptive_mixup(batch_size, aug_params, images, labels):
229228 # Need to filter out elements in alpha which equal to 0.
230229 greater_zero_indicator = tf .cast (alpha > 0 , alpha .dtype )
231230 less_one_indicator = tf .cast (alpha < 1 , alpha .dtype )
232- valid_alpha_indicator = tf .cast (
233- greater_zero_indicator * less_one_indicator , tf .bool )
231+ valid_alpha_indicator = tf .cast (greater_zero_indicator * less_one_indicator ,
232+ tf .bool )
234233 sampled_alpha = tf .where (valid_alpha_indicator , alpha , 0.1 )
235234 mix_weight = tfd .Beta (sampled_alpha , sampled_alpha ).sample ()
236235 mix_weight = tf .where (valid_alpha_indicator , mix_weight , alpha )
@@ -253,4 +252,5 @@ def adaptive_mixup(batch_size, aug_params, images, labels):
253252 images_mix = (
254253 images * images_mix_weight + images [::- 1 ] * (1. - images_mix_weight ))
255254 labels_mix = labels * mix_weight + labels [::- 1 ] * (1. - mix_weight )
256- return images_mix , labels_mix
255+
256+ return images_mix , labels_mix
0 commit comments