-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
60 lines (44 loc) · 1.78 KB
/
run.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
import logging
import click
from saticl import testing, training
from saticl.cli import command
from saticl.config import Configuration, SSLConfiguration, TestConfiguration
from saticl.preproc import isaid, isprs
from saticl.preproc.config import ISAIDPreprocConfig, ISPRSPreprocConfig
from tqdm.contrib.logging import logging_redirect_tqdm
INFO_FMT = "%(asctime)s - %(name)s [%(levelname)s]: %(message)s"
DEBUG_FMT = "%(asctime)s - %(pathname)s (%(funcName)s) [%(levelname)s]: %(message)s"
DATE_FMT = "%Y-%m-%d %H:%M"
def init_logging(log_level: int, log_format: str, date_format: str) -> None:
logging.basicConfig(level=log_level, format=log_format, datefmt=date_format)
logging.root.setLevel(log_level)
@click.group()
def cli():
pass
@command(config=ISPRSPreprocConfig)
def prepare_isprs(config: ISPRSPreprocConfig):
init_logging(logging.INFO, INFO_FMT, DATE_FMT)
isprs.main(config)
@command(config=ISAIDPreprocConfig)
def prepare_isaid(config: ISAIDPreprocConfig):
init_logging(logging.INFO, INFO_FMT, DATE_FMT)
isaid.main(config)
@command(config=Configuration)
def train(config: Configuration):
log_level = logging.DEBUG if config.debug else logging.INFO
log_format = DEBUG_FMT if config.debug else INFO_FMT
init_logging(log_level, log_format, DATE_FMT)
return training.train(config)
@command(config=TestConfiguration)
def test(config: TestConfiguration):
log_level = logging.DEBUG if config.debug else logging.INFO
log_format = DEBUG_FMT if config.debug else INFO_FMT
init_logging(log_level, log_format, DATE_FMT)
return testing.test(config)
if __name__ == "__main__":
cli.add_command(prepare_isprs)
cli.add_command(prepare_isaid)
cli.add_command(train)
cli.add_command(test)
with logging_redirect_tqdm():
cli()