-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtools.py
59 lines (51 loc) · 1.47 KB
/
tools.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
import multiprocessing
import os
import numpy as np
import pandas as pd
def initialise_multithread(num_cores=-1):
"""
Initialise pool workers for multi processing
:param num_cores:
:return:
"""
if (num_cores == -1) or (num_cores >= multiprocessing.cpu_count()):
num_cores = multiprocessing.cpu_count() - 1
p = multiprocessing.Pool(num_cores)
return p
def create_directory(directory_path):
"""
Create a directory if path doesn't exists
:param directory_path:
:return:
"""
if os.path.exists(directory_path):
return None
else:
try:
os.makedirs(directory_path)
except:
# in case another machine created the path meanwhile !:(
return None
return directory_path
def save_train_duration(file_name, test_duration):
"""
Save training time
:param file_name:
:param test_duration:
:return:
"""
res = pd.DataFrame(data=np.zeros((1, 1), dtype=np.float), index=[0],
columns=['train_duration'])
res['train_duration'] = test_duration
res.to_csv(file_name, index=False)
def save_test_duration(file_name, test_duration):
"""
Save test time
:param file_name:
:param test_duration:
:return:
"""
res = pd.DataFrame(data=np.zeros((1, 1), dtype=np.float), index=[0],
columns=['test_duration'])
res['test_duration'] = test_duration
res.to_csv(file_name, index=False)