This repository has been archived by the owner on Apr 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
04-prediction.py
53 lines (41 loc) · 1.45 KB
/
04-prediction.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
from ops.ops import load_json, create_exps_paths, load_exp
import os
import multiprocessing
from pred import predict
import fiona
import tqdm
import logging
if __name__ == '__main__':
exp = load_exp()
exp_n = exp['exp_n']
exps_path, exp_path, models_path, results_path, predictions_path, visual_path, logs_path = create_exps_paths(exp_n)
conf = load_json(os.path.join('conf', 'conf.json'))
img_source = conf['img_source']
paths = load_json(os.path.join('conf', 'paths.json'))
shp_path = paths['shp']
img_path = paths['img']
shp = load_json(os.path.join('conf', 'shp.json'))
grid_shp = shp[f'shp_download_{img_source}']
grid_save = os.path.join(shp_path, f"{grid_shp}.shp")
log_file = os.path.join(exp_path, f'pred.txt')
if os.path.exists(log_file):
os.remove(log_file)
logging.basicConfig(
filename=log_file,
level=logging.INFO,
filemode='a',
format='%(asctime)s - %(message)s',
datefmt='%d-%b-%y %H:%M:%S'
)
#n_models = conf['n_models']
test_feats = []
with fiona.open(grid_save) as grid:
for feat in grid:
feat_id = int(feat['properties']['id'])
#if feat['properties']['dataset'] == 0:
test_feats.append(feat_id)
for feat_id in tqdm.tqdm(test_feats):
#predict(feat_id)
p = multiprocessing.Process(target=predict, args=(feat_id,))
p.start()
p.join()