-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
48 lines (40 loc) · 1.6 KB
/
utils.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
import csv
import os
import shutil
class Setup:
def dir_setup(dir_list):
for directory in dir_list:
if not os.path.isdir(directory):
os.mkdir(directory)
print(f"Created {directory}")
else:
print(f"Skipped {directory}. It already exists")
# Delete default Colab sample data folder
if os.path.exists('sample_data'):
shutil.rmtree('sample_data')
class Diag:
import csv
import os
def setup(file_path):
# logwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
# pass
loss_log = file_path
log_headers = ["Time", "Learning Rate", "Loss"]
if not os.path.exists(loss_log):
print(f"Creating new log at {loss_log}")
with open(loss_log, 'w', newline='') as csvfile:
logwriter = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
logwriter.writerow(log_headers)
else:
print(f"Using existing log")
def write_row(data, file_path):
"""
@param: data: list of data you want written to a row, one datum per column
@param: file_path: path to the CSV file you want to write to
"""
if not os.path.exists(file_path):
raise IOError(f"File {file_path} not found")
else:
with open(file_path, 'a', newline='') as csvfile:
logwriter = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
logwriter.writerow(data)