-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
156 lines (116 loc) · 4.53 KB
/
config.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import os
from pathlib import Path
from pymongo import ASCENDING, GEOSPHERE, IndexModel, MongoClient
from tinydb import TinyDB
from orjson_storage import ORJSONStorage
SEED = 42
SAVE_IMG = os.getenv('SAVE_IMG', '0') == '1'
DRY_RUN = os.getenv('DRY_RUN', '0') == '1'
DAILY_IMPORT_SPEED = float(os.getenv('DAILY_IMPORT_SPEED', '300'))
MIN_IMPORT_SIZE = int(os.getenv('MIN_IMPORT_SIZE', '40'))
MIN_SLEEP_AFTER_IMPORT = float(os.getenv('MIN_SLEEP_AFTER_IMPORT', '300')) # let overpass-api update
SLEEP_AFTER_GRID_ITER = float(os.getenv('SLEEP_DAYS_AFTER_GRID_ITER', '30')) * 24 * 3600
PROCESS_NICE = int(os.getenv('PROCESS_NICE', '15'))
RETRY_TIME_LIMIT = float(os.getenv('RETRY_TIME_LIMIT', '28800')) # 8h
BACKLOG_FACTOR = int(os.getenv('BACKLOG_FACTOR', '4'))
GRID_OVERLAP = 0.1
if DRY_RUN:
print('🦺 TEST MODE 🦺')
else:
print('🔴 PRODUCTION MODE 🔴')
# Dedicated instance unavailable? Pick one from the public list:
# https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances
OVERPASS_API_INTERPRETER = os.getenv('OVERPASS_API_INTERPRETER', 'https://overpass.monicz.dev/api/interpreter')
OSM_USERNAME = os.getenv('OSM_USERNAME')
OSM_PASSWORD = os.getenv('OSM_PASSWORD')
if not OSM_PASSWORD or not OSM_PASSWORD:
print('⚠️ OpenStreetMap credentials are not set')
SEARCH_RELATION = 49715 # Poland
CPU_COUNT = min(int(os.getenv('CPU_COUNT', '1')), len(os.sched_getaffinity(0)))
MAX_TASKS_PER_CHILD = int(os.getenv('MAX_TASKS_PER_CHILD', '300'))
SCORER_VERSION = 3 # changing this will invalidate previous results
VERSION = '1.6.2'
NAME = 'osm-yolo-crossings'
CREATED_BY = f'{NAME} {VERSION}'
WEBSITE = 'https://github.com/Zaczero/osm-yolo-crossings'
USER_AGENT = f'{NAME}/{VERSION} (+{WEBSITE})'
CHANGESET_ID_PLACEHOLDER = '__CHANGESET_ID_PLACEHOLDER__'
DEFAULT_CHANGESET_TAGS = {
'comment': 'Import przejść dla pieszych z ortofotomapy',
'created_by': CREATED_BY,
'import': 'yes',
'source': 'aerial imagery',
'website': WEBSITE,
'website:import': 'https://wiki.openstreetmap.org/wiki/YOLO_crossings_import',
}
DATA_DIR = Path('data')
DATA_DIR.mkdir(exist_ok=True)
CACHE_DIR = DATA_DIR / 'cache'
CACHE_DIR.mkdir(exist_ok=True)
IMAGES_DIR = Path('images')
IMAGES_DIR.mkdir(exist_ok=True)
DATASET_DIR = Path('dataset')
DATASET_DIR.mkdir(exist_ok=True)
YOLO_DATASET_DIR = DATASET_DIR / 'YOLO'
YOLO_DATASET_DIR.mkdir(exist_ok=True)
ATTRIB_DATASET_DIR = DATASET_DIR / 'ATTRIB'
ATTRIB_DATASET_DIR.mkdir(exist_ok=True)
MODEL_DIR = Path('model')
MODEL_DIR.mkdir(exist_ok=True)
YOLO_MODEL_PATH = MODEL_DIR / 'yolo.keras'
YOLO_MODEL_RESOLUTION = 224
YOLO_CONFIDENCE = 0.4
ATTRIB_POSITION_EXTEND = 9 # meters
ATTRIB_MODEL_PATH = MODEL_DIR / 'attrib.h5'
ATTRIB_MODEL_RESOLUTION = 224
ATTRIB_PRECISION = 0.998
ATTRIB_CONFIDENCE = 0.995
ATTRIB_NUM_CLASSES = 2
# ATTRIB_PRECISION = (
# 0.995, # valid
# 0.995, # signals
# )
# ATTRIB_CONFIDENCES = (
# 0.730, # valid
# (0.060, 1.111), # signals (..., 0.995)
# )
GRID_FILTER_BUILDING_DISTANCE = 1000 # meters
GRID_FILTER_ROAD_INTERPOLATE = 10 # meters
_RANGE = 5 # meters
ADDED_SEARCH_RADIUS = _RANGE + 0.05 # meters
CROSSING_BOX_EXTEND = 15 # meters
# see for picking good values: https://www.openstreetmap.org/node/4464489698
# maximum distance from the center of the box to a road
BOX_VALID_MAX_CENTER_DISTANCE = _RANGE # meters
# maximum angle between raods before considering the case too complex
BOX_VALID_MAX_ROAD_ANGLE = 40 # degrees
# maximum intersection count for a perpendicular section
BOX_VALID_MAX_ROAD_COUNT = 2
# minimum distance between crossings (circular)
BOX_VALID_MIN_CROSSING_DISTANCE = _RANGE # meters
# minimum distance between crossings (cone)
BOX_VALID_MIN_CROSSING_DISTANCE_CONE = 15 # meters
BOX_VALID_MIN_CROSSING_DISTANCE_CONE_ANGLE = 30 # degrees
# maximum distance to reuse an existing node
NODE_MERGE_THRESHOLD = 1.5 # meters
# maximum distance to reuse an existing node, if it's also used by a path/footway/...
NODE_MERGE_THRESHOLD_PRIORITY = _RANGE # meters
DB_PATH = DATA_DIR / 'db.json'
DB = TinyDB(DB_PATH, storage=ORJSONStorage)
DB_GRID = DB.table('grid')
MONGO_URL = os.getenv('MONGO_URL', 'mongodb://localhost:27017')
MONGO = MongoClient(MONGO_URL)
MONGO_DB = MONGO[NAME]
MONGO_ADDED = MONGO_DB['added']
if MONGO_URL != 'IGNORE':
try:
MONGO_ADDED.drop_index([('scorer_version', ASCENDING)])
except Exception:
pass
try:
MONGO_ADDED.drop_index([('reason', ASCENDING)])
except Exception:
pass
MONGO_ADDED.create_indexes([
IndexModel([('position', GEOSPHERE)]),
])