-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_data_distribution.py
129 lines (105 loc) · 5.28 KB
/
generate_data_distribution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from loguru import logger
import pathlib
import os
from federated_learning.arguments import Arguments
from federated_learning.datasets import CIFAR10Dataset
from federated_learning.datasets import CIFAR100Dataset
from federated_learning.datasets import FashionMNISTDataset
# from federated_learning.datasets import TRECDataset
from federated_learning.utils import generate_train_loader
from federated_learning.utils import generate_test_loader
from federated_learning.utils import save_data_loader_to_file
if __name__ == '__main__':
args = Arguments(logger)
# ---------------------------------
# ------------ CIFAR10 ------------
# ---------------------------------
dataset = CIFAR10Dataset(args)
TRAIN_DATA_LOADER_FILE_PATH = "data_loaders/cifar10/train_data_loader.pickle"
TEST_DATA_LOADER_FILE_PATH = "data_loaders/cifar10/test_data_loader.pickle"
if not os.path.exists("data_loaders/cifar10"):
pathlib.Path("data_loaders/cifar10").mkdir(parents=True, exist_ok=True)
train_data_loader = generate_train_loader(args, dataset)
test_data_loader = generate_test_loader(args, dataset)
with open(TRAIN_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(train_data_loader, f)
with open(TEST_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(test_data_loader, f)
# ---------------------------------
# --------- Fashion-MNIST ---------
# ---------------------------------
dataset = FashionMNISTDataset(args)
TRAIN_DATA_LOADER_FILE_PATH = "data_loaders/fashion-mnist/train_data_loader.pickle"
TEST_DATA_LOADER_FILE_PATH = "data_loaders/fashion-mnist/test_data_loader.pickle"
if not os.path.exists("data_loaders/fashion-mnist"):
pathlib.Path("data_loaders/fashion-mnist").mkdir(parents=True, exist_ok=True)
train_data_loader = generate_train_loader(args, dataset)
test_data_loader = generate_test_loader(args, dataset)
with open(TRAIN_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(train_data_loader, f)
with open(TEST_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(test_data_loader, f)
# ---------------------------------
# ------------ MNIST --------------
# ---------------------------------
dataset = FashionMNISTDataset(args)
TRAIN_DATA_LOADER_FILE_PATH = "data_loaders/mnist/train_data_loader.pickle"
TEST_DATA_LOADER_FILE_PATH = "data_loaders/mnist/test_data_loader.pickle"
if not os.path.exists("data_loaders/mnist"):
pathlib.Path("data_loaders/mnist").mkdir(parents=True, exist_ok=True)
train_data_loader = generate_train_loader(args, dataset)
test_data_loader = generate_test_loader(args, dataset)
with open(TRAIN_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(train_data_loader, f)
with open(TEST_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(test_data_loader, f)
# ---------------------------------
# ------------ STL10 --------------
# ---------------------------------
dataset = FashionMNISTDataset(args)
TRAIN_DATA_LOADER_FILE_PATH = "data_loaders/stl10/train_data_loader.pickle"
TEST_DATA_LOADER_FILE_PATH = "data_loaders/stl10/test_data_loader.pickle"
if not os.path.exists("data_loaders/stl10"):
pathlib.Path("data_loaders/stl10").mkdir(parents=True, exist_ok=True)
train_data_loader = generate_train_loader(args, dataset)
test_data_loader = generate_test_loader(args, dataset)
with open(TRAIN_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(train_data_loader, f)
with open(TEST_DATA_LOADER_FILE_PATH, "wb") as f:
save_data_loader_to_file(test_data_loader, f)
# ---------------------------------
# ------------ CIFAR100 -----------
# ---------------------------------
# dataset = CIFAR100Dataset(args)
# TRAIN_DATA_LOADER_FILE_PATH = "data_loaders/cifar100/train_data_loader.pickle"
# TEST_DATA_LOADER_FILE_PATH = "data_loaders/cifar100/test_data_loader.pickle"
#
# if not os.path.exists("data_loaders/cifar100"):
# pathlib.Path("data_loaders/cifar100").mkdir(parents=True, exist_ok=True)
#
# train_data_loader = generate_train_loader(args, dataset)
# test_data_loader = generate_test_loader(args, dataset)
#
# with open(TRAIN_DATA_LOADER_FILE_PATH, "wb") as f:
# save_data_loader_to_file(train_data_loader, f)
#
# with open(TEST_DATA_LOADER_FILE_PATH, "wb") as f:
# save_data_loader_to_file(test_data_loader, f)
# ---------------------------------
# ---------------TREC -------------
# ---------------------------------
# dataset = TRECDataset(args)
# TRAIN_DATA_LOADER_FILE_PATH = "data_loaders/trec/train_data_loader.pickle"
# TEST_DATA_LOADER_FILE_PATH = "data_loaders/trec/test_data_loader.pickle"
#
# if not os.path.exists("data_loaders/trec"):
# pathlib.Path("data_loaders/trec").mkdir(parents=True, exist_ok=True)
#
# train_data_loader = generate_train_loader(args, dataset)
# test_data_loader = generate_test_loader(args, dataset)
#
# with open(TRAIN_DATA_LOADER_FILE_PATH, "wb") as f:
# save_data_loader_to_file(train_data_loader, f)
#
# with open(TEST_DATA_LOADER_FILE_PATH, "wb") as f:
# save_data_loader_to_file(test_data_loader, f)