-
Notifications
You must be signed in to change notification settings - Fork 11
/
run.py
49 lines (36 loc) · 1.37 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
import os
import sys
import logging
from data import Datasets
from utils import configuration
from trainer import QuasiSiameseNetwork
# logging
logger = logging.getLogger(__name__)
logging.getLogger('Fiona').setLevel(logging.ERROR)
logging.getLogger('fiona.collection').setLevel(logging.ERROR)
logging.getLogger('rasterio').setLevel(logging.ERROR)
logging.getLogger('PIL.PngImagePlugin').setLevel(logging.ERROR)
def exceptionLogger(exceptionType, exceptionValue, exceptionTraceback):
logger.error("Uncaught Exception", exc_info=(
exceptionType, exceptionValue, exceptionTraceback))
sys.excepthook = exceptionLogger
if __name__ == '__main__':
args = configuration()
logging.basicConfig(
handlers=[
logging.FileHandler(os.path.join(args.checkpointPath, 'run.log')),
logging.StreamHandler(sys.stdout)
],
level=logging.DEBUG,
format='%(asctime)s %(name)s %(levelname)s %(message)s'
)
logger.info('START with Configuration : {}'.format(args))
qsn = QuasiSiameseNetwork(args)
datasets = Datasets(args, qsn.transforms)
save_path = os.path.join(args.checkpointPath, "best_model_wts.pkl")
if args.test:
logger.info("Testing the model")
qsn.test(datasets, args.device, save_path)
else:
qsn.train(args.numberOfEpochs, datasets, args.device, save_path)
logger.info('END')