-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign_to_sets.py
41 lines (33 loc) · 1.27 KB
/
assign_to_sets.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
import argparse
import random
import database
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--database', default='data/tiles.db')
parser.add_argument('--feature', default='solar')
args = parser.parse_args()
db = database.Database(args.database)
with db.transaction('get_tiles_for_assignment') as c:
c.execute('''select z, x, y
from last_update''')
positions = [(args.feature, z, x, y)
for z, x, y
in c.fetchall()]
random.shuffle(positions)
print(f'Positions: {len(positions)}')
validation_size = int(len(positions) / 10)
validation = positions[:validation_size]
print(f'Validation: {len(validation)}')
training = positions[validation_size:]
print(f'Training: {len(training)}')
with db.transaction('write_tile_assignments') as c:
c.executemany('''insert into validation_set
(feature_name, z, x, y)
values (?, ?, ?, ?)''',
validation)
c.executemany('''insert into training_set
(feature_name, z, x, y)
values (?, ?, ?, ?)''',
training)
if __name__ == '__main__':
main()