MCPcopy Create free account
hub / github.com/DanielShalam/BPA / loadDataSet

Function loadDataSet

methods/pt_map/FSLTask.py:43–74  ·  view source on GitHub ↗
(dsname, root: str = None, features_path: str = None)

Source from the content-addressed store, hash-verified

41
42
43def loadDataSet(dsname, root: str = None, features_path: str = None):
44 global dsName, data, labels, _randStates, _rsCfg, _min_examples, _cacheDir
45 dsName = dsname
46 _randStates = None
47 _rsCfg = None
48 _cacheDir = root + '/methods/pt_map/cache'
49
50 # Loading data from files on computer
51 if features_path is None or features_path == '':
52 if dsname not in data_features_path:
53 raise NameError('Unknwown dataset: {}'.format(dsname))
54 features_path = data_features_path[dsname]
55
56 dataset = _load_pickle(features_path)
57
58 # Computing the number of items per class in the dataset
59 _min_examples = dataset["labels"].shape[0]
60 for i in range(dataset["labels"].shape[0]):
61 if torch.where(dataset["labels"] == dataset["labels"][i])[0].shape[0] > 0:
62 _min_examples = min(_min_examples, torch.where(
63 dataset["labels"] == dataset["labels"][i])[0].shape[0])
64 print("Guaranteed number of items per class: {:d}\n".format(_min_examples))
65
66 # Generating data tensors
67 data = torch.zeros((0, _min_examples, dataset["data"].shape[1]))
68 labels = dataset["labels"].clone()
69 while labels.shape[0] > 0:
70 indices = torch.where(dataset["labels"] == labels[0])[0]
71 data = torch.cat([data, dataset["data"][indices, :][:_min_examples].view(1, _min_examples, -1)], dim=0)
72 indices = torch.where(labels != labels[0])[0]
73 labels = labels[indices]
74 print("Total of {:d} classes, {:d} elements each, with dimension {:d}\n".format(data.shape[0], data.shape[1], data.shape[2]))
75
76
77def GenerateRun(iRun, cfg, regenRState=False, generate=True):

Callers

nothing calls this directly

Calls 2

_load_pickleFunction · 0.85
cloneMethod · 0.45

Tested by

no test coverage detected