I have two datasets dictionary like this:
D1 = {'query': torch.tensor([(1, 2)], dtype=torch.float32),
'support': torch.tensor([(2, 4), (3, 1)], dtype=torch.float32)} # (x, y) pairs for query (Q1) and support (S1) set.
D2 = {'query': torch.tensor([(4, 1)], dtype=torch.float32), 'support': torch.tensor([(5, 3), (6, 0)], dtype=torch.float32)}
in which it has two datapoints for support (subset) used in training and one datapoint for query subset (used during the test/validation). I wanna extend my experiment with more datasets and increase the number of random samples in each subset. Is there any way to automate the generation of datasets to 100 and data points?
Thanks
CodePudding user response:
You can achieve this by using random
module from numpy
and loops.
import torch
import numpy as np
data = {}
n = 100
for i in range(1, n):
t1 = (np.random.randint(0,9), np.random.randint(0,9))
t2 = (np.random.randint(0,9), np.random.randint(0,9))
t3 = (np.random.randint(0,9), np.random.randint(0,9))
D = {'query': torch.tensor([t1], dtype=torch.float32),
'support': torch.tensor([t2, t3], dtype=torch.float32)} # (x, y) pairs for query (Q1) and support (S1) set.
data[f"D{i}"] = D
print(data)
You can customize the random number based on your use case.