Skip to content

Commit c06274e

Browse files
committed
Add note on random selection of magnitude value
1 parent b750b76 commit c06274e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

timm/data/auto_augment.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,22 @@ def __init__(self, name, prob, magnitude, hparams={}):
251251
self.level_fn = level_to_arg(hparams)[name]
252252
self.prob = prob
253253
self.magnitude = magnitude
254+
# If std deviation of magnitude is > 0, we introduce some randomness
255+
# in the usually fixed policy and sample magnitude from normal dist
256+
# with mean magnitude and std-dev of magnitude_std.
257+
# NOTE This is being tested as it's not in paper or reference impl.
258+
self.magnitude_std = 0.5 # FIXME add arg/hparam
254259
self.kwargs = {
255260
'fillcolor': hparams['img_mean'] if 'img_mean' in hparams else _FILL,
256261
'resample': hparams['interpolation'] if 'interpolation' in hparams else _RANDOM_INTERPOLATION
257262
}
258-
self.rand_magnitude = True
259263

260264
def __call__(self, img):
261265
if self.prob < random.random():
262266
return img
263267
magnitude = self.magnitude
264-
if self.rand_magnitude:
265-
magnitude = random.normalvariate(magnitude, 0.5)
268+
if self.magnitude_std and self.magnitude_std > 0:
269+
magnitude = random.gauss(magnitude, self.magnitude_std)
266270
magnitude = min(_MAX_LEVEL, max(0, magnitude))
267271
level_args = self.level_fn(magnitude)
268272
return self.aug_fn(img, *level_args, **self.kwargs)

0 commit comments

Comments
 (0)