-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTraining_Validation_Generator.py
More file actions
35 lines (26 loc) · 1008 Bytes
/
Training_Validation_Generator.py
File metadata and controls
35 lines (26 loc) · 1008 Bytes
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
import json
from pprint import pprint
import random
import itertools
with open('Getty_Gold_time.json') as data_file:
data = json.load(data_file)
def random_generator(seq, n, m):
rand_seq = seq[:] # make a copy to avoid changing input argument
random.shuffle(rand_seq)
lists = []
limit = n-1
for i,group in enumerate(itertools.izip(*([iter(rand_seq)]*m))):
lists.append(group)
if i == limit: break # have enough
return lists
training1, training2, training3, training4 = (random_generator(data, 4, 110057))
with open('Getty_Training1.json', 'w') as outfile:
json.dump(training1, outfile, sort_keys = True, indent = 4,
ensure_ascii=False)
with open('Getty_Training2.json', 'w') as outfile:
json.dump(training2, outfile, sort_keys = True, indent = 4,
ensure_ascii=False)
validation = [training3, training4]
with open('Getty_Validation.json', 'w') as outfile:
json.dump(validation, outfile, sort_keys = True, indent = 4,
ensure_ascii=False)