|
a |
|
b/Projects/Caffe/allCNN/Classes/Helpers.py |
|
|
1 |
############################################################################################ |
|
|
2 |
# |
|
|
3 |
# The MIT License (MIT) |
|
|
4 |
# |
|
|
5 |
# Peter Moss Acute Myeloid/Lymphoblastic Leukemia AI Research Project |
|
|
6 |
# Copyright (C) 2018 Adam Milton-Barker (AdamMiltonBarker.com) |
|
|
7 |
# |
|
|
8 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
|
9 |
# of this software and associated documentation files (the "Software"), to deal |
|
|
10 |
# in the Software without restriction, including without limitation the rights |
|
|
11 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
|
12 |
# copies of the Software, and to permit persons to whom the Software is |
|
|
13 |
# furnished to do so, subject to the following conditions: |
|
|
14 |
# |
|
|
15 |
# The above copyright notice and this permission notice shall be included in |
|
|
16 |
# all copies or substantial portions of the Software. |
|
|
17 |
# |
|
|
18 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
|
19 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
|
20 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
|
21 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
|
22 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
|
23 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
|
24 |
# THE SOFTWARE. |
|
|
25 |
# |
|
|
26 |
# Title: Caffe Acute Lymphoblastic Leukemia CNN Helpers |
|
|
27 |
# Description: Common tools used by the Caffe Acute Lymphoblastic Leukemia CNN |
|
|
28 |
# Configuration: Required/Confs.json |
|
|
29 |
# Last Modified: 2019-03-10 |
|
|
30 |
# |
|
|
31 |
############################################################################################ |
|
|
32 |
|
|
|
33 |
import json, time |
|
|
34 |
|
|
|
35 |
from datetime import datetime |
|
|
36 |
|
|
|
37 |
class Helpers(): |
|
|
38 |
|
|
|
39 |
def __init__(self): |
|
|
40 |
|
|
|
41 |
""" |
|
|
42 |
Sets up all default requirements and placeholders |
|
|
43 |
needed for the Caffe Acute Lymphoblastic Leukemia CNN Helpers. |
|
|
44 |
""" |
|
|
45 |
|
|
|
46 |
pass |
|
|
47 |
|
|
|
48 |
def loadConfs(self): |
|
|
49 |
|
|
|
50 |
""" |
|
|
51 |
Load the allCNN Classifier configuration. |
|
|
52 |
""" |
|
|
53 |
|
|
|
54 |
confs = {} |
|
|
55 |
with open('Required/Confs.json') as confs: |
|
|
56 |
confs = json.loads(confs.read()) |
|
|
57 |
return confs |
|
|
58 |
|
|
|
59 |
def currentDateTime(self): |
|
|
60 |
|
|
|
61 |
""" |
|
|
62 |
Gets the current date and time in words. |
|
|
63 |
""" |
|
|
64 |
|
|
|
65 |
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
66 |
|
|
|
67 |
def timerStart(self): |
|
|
68 |
|
|
|
69 |
""" |
|
|
70 |
Starts a timer. |
|
|
71 |
""" |
|
|
72 |
|
|
|
73 |
return str(datetime.now()), time.time() |
|
|
74 |
|
|
|
75 |
def timerEnd(self, start): |
|
|
76 |
|
|
|
77 |
""" |
|
|
78 |
Starts the timer. |
|
|
79 |
""" |
|
|
80 |
|
|
|
81 |
return time.time(), (time.time() - start), str(datetime.now()) |
|
|
82 |
|
|
|
83 |
def setLogFile(self, path): |
|
|
84 |
|
|
|
85 |
""" |
|
|
86 |
Sets a log file path. |
|
|
87 |
""" |
|
|
88 |
|
|
|
89 |
return path + datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d-%H-%M-%S') + ".txt" |
|
|
90 |
|
|
|
91 |
def logMessage(self, logfile, process, messageType, message, hide = False): |
|
|
92 |
|
|
|
93 |
""" |
|
|
94 |
Logs a message to a log file. |
|
|
95 |
""" |
|
|
96 |
|
|
|
97 |
logString = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') + "|" + process + "|" + messageType + ": " + message |
|
|
98 |
with open(logfile,"a") as logLine: |
|
|
99 |
logLine.write(logString+'\r\n') |
|
|
100 |
if hide == False: |
|
|
101 |
print(logString) |