-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.py
63 lines (53 loc) · 1.79 KB
/
data.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
import os
import sys
import argparse
import pandas as pd
sys.path.insert(0, "./utils/")
import config
import geoutils
import logging
def main(c):
logname = os.path.join(c['log_dir'], f"{c['config_name']}.log")
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
handler = logging.FileHandler(logname)
handler.setLevel(logging.INFO)
logger.addHandler(handler)
img_srcs = c['img_srcs']
for img_src in img_srcs:
filename = f"{c['config_name']}.csv"
tile_path = os.path.join(c['tile_dir'], c['config_name'])
out_file = os.path.join(c['csv_dir'], filename)
data = []
src_file = c[f'{img_src}_source_files']
for index, source_file in enumerate(src_file):
logging.info(c['aois'][index])
bldgs = geoutils.get_annotated_bldgs(config=c, index=index)
source_path = os.path.join(c['rasters_dir'], source_file)
subdata = geoutils.generate_image_crops(
bldgs,
in_file=source_path,
aoi=c['aois'][index],
out_path=tile_path
)
data.append(subdata)
data = pd.concat(data)
geoutils.generate_train_test(
data,
attributes=c['attributes'],
out_dir=c['csv_dir'],
test_size=c['test_size'],
test_aoi=c['test_aoi'],
test_src=c['test_src'],
stratified=True
)
data.to_csv(out_file, index=False)
if __name__ == "__main__":
# Parser
parser = argparse.ArgumentParser(description="Data Generation")
parser.add_argument("--config", help="Config file")
args = parser.parse_args()
# Load config
c = config.load_config(args.config)
logging.info(c)
main(c)