Skip to content

Instantly share code, notes, and snippets.

@tokestermw
Last active December 1, 2019 07:04
Show Gist options
  • Save tokestermw/736dc2b629f9e3a6a53c19d345eccb98 to your computer and use it in GitHub Desktop.
Save tokestermw/736dc2b629f9e3a6a53c19d345eccb98 to your computer and use it in GitHub Desktop.
import random
def augmentation_fun(x, augment_by=3):
# augment the original data point by 3
return [x + random.random() * 2 - 1 for i in range(augment_by)]
def train_loop(dataset, do_augment=False):
# emit one data point at a time
for x in dataset:
# ... preprocess, etc.
if do_augment:
yield from augmentation_fun(x)
else:
yield x
if __name__ == "__main__":
dataset = [1, 2, 3]
for x in train_loop(dataset, do_augment=True):
print(x)
# 1.6910669464085353
# 0.6755471610373542
# 1.3990163430931686
# 1.0574266964192516
# 1.7474122098401583
# 2.8820668623545096
# 3.0684208172249834
# 2.0069288129912817
# 3.7746658889260774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment