|
a |
|
b/Classifier/Classes/Helpers.py |
|
|
1 |
############################################################################################ |
|
|
2 |
# |
|
|
3 |
# Project: Peter Moss Acute Myeloid & Lymphoblastic Leukemia AI Research Project |
|
|
4 |
# Repository: ALL Detection System 2020 |
|
|
5 |
# Project: AllDS2020 Classifier |
|
|
6 |
# |
|
|
7 |
# Author: Adam Milton-Barker (AdamMiltonBarker.com) |
|
|
8 |
# Contributors: |
|
|
9 |
# Title: Helper Class |
|
|
10 |
# Description: Helper functions for the Acute Lymphoblastic Leukemia Tensorflow CNN 2020 |
|
|
11 |
# ALL Classifier. |
|
|
12 |
# License: MIT License |
|
|
13 |
# Last Modified: 2020-07-23 |
|
|
14 |
# |
|
|
15 |
############################################################################################ |
|
|
16 |
|
|
|
17 |
import sys |
|
|
18 |
import time |
|
|
19 |
import logging |
|
|
20 |
import logging.handlers as handlers |
|
|
21 |
import json |
|
|
22 |
|
|
|
23 |
from datetime import datetime |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
class Helpers(): |
|
|
27 |
""" Helper Class |
|
|
28 |
|
|
|
29 |
Helper functions for the ALL Detection System 2020 ALL Classifier. |
|
|
30 |
""" |
|
|
31 |
|
|
|
32 |
def __init__(self, ltype, log=True): |
|
|
33 |
""" Initializes the Helpers Class. """ |
|
|
34 |
|
|
|
35 |
self.config = {} |
|
|
36 |
self.loadConfs() |
|
|
37 |
|
|
|
38 |
self.logger = logging.getLogger(ltype) |
|
|
39 |
self.logger.setLevel(logging.INFO) |
|
|
40 |
|
|
|
41 |
formatter = logging.Formatter( |
|
|
42 |
'%(asctime)s - %(name)s - %(levelname)s - %(message)s') |
|
|
43 |
|
|
|
44 |
allLogHandler = handlers.TimedRotatingFileHandler( |
|
|
45 |
'Logs/all.log', when='H', interval=1, backupCount=0) |
|
|
46 |
allLogHandler.setLevel(logging.INFO) |
|
|
47 |
allLogHandler.setFormatter(formatter) |
|
|
48 |
|
|
|
49 |
errorLogHandler = handlers.TimedRotatingFileHandler( |
|
|
50 |
'Logs/error.log', when='H', interval=1, backupCount=0) |
|
|
51 |
errorLogHandler.setLevel(logging.ERROR) |
|
|
52 |
errorLogHandler.setFormatter(formatter) |
|
|
53 |
|
|
|
54 |
warningLogHandler = handlers.TimedRotatingFileHandler( |
|
|
55 |
'Logs/warning.log', when='H', interval=1, backupCount=0) |
|
|
56 |
warningLogHandler.setLevel(logging.WARNING) |
|
|
57 |
warningLogHandler.setFormatter(formatter) |
|
|
58 |
|
|
|
59 |
consoleHandler = logging.StreamHandler(sys.stdout) |
|
|
60 |
consoleHandler.setFormatter(formatter) |
|
|
61 |
|
|
|
62 |
self.logger.addHandler(allLogHandler) |
|
|
63 |
self.logger.addHandler(errorLogHandler) |
|
|
64 |
self.logger.addHandler(warningLogHandler) |
|
|
65 |
self.logger.addHandler(consoleHandler) |
|
|
66 |
|
|
|
67 |
if log is True: |
|
|
68 |
self.logger.info("Helpers class initialization complete.") |
|
|
69 |
|
|
|
70 |
def loadConfs(self): |
|
|
71 |
""" Load the program configuration. """ |
|
|
72 |
|
|
|
73 |
with open('/home/allen/Drive C/Peter Moss AML Leukemia Research/ALL-PyTorch-2020/Classifier/Model/config.json') as confs: |
|
|
74 |
self.config = json.loads(confs.read()) |