Skip to content
Snippets Groups Projects

finish run script creation, /close #11

Merged Ghost User requested to merge lukas_issue011_feat_run-script into develop
5 files
+ 344
1
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 85
0
@@ -9,6 +9,9 @@ import math
@@ -9,6 +9,9 @@ import math
from typing import Union
from typing import Union
import numpy as np
import numpy as np
import os
import os
 
import time
 
import socket
 
import sys
def to_list(arg):
def to_list(arg):
@@ -84,3 +87,85 @@ class LearningRateDecay(keras.callbacks.History):
@@ -84,3 +87,85 @@ class LearningRateDecay(keras.callbacks.History):
self.lr['lr'].append(current_lr)
self.lr['lr'].append(current_lr)
logging.info(f"Set learning rate to {current_lr}")
logging.info(f"Set learning rate to {current_lr}")
return K.get_value(self.model.optimizer.lr)
return K.get_value(self.model.optimizer.lr)
 
 
 
class TimeTracking(object):
 
"""
 
Track time to measure execution time. Time tracking automatically starts on initialisation and ends by calling stop
 
method. Duration can always be shown by printing the time tracking object or calling get_current_duration.
 
"""
 
 
def __init__(self, start=True):
 
self.start = None
 
self.end = None
 
if start:
 
self._start()
 
 
def _start(self):
 
self.start = time.time()
 
self.end = None
 
 
def _end(self):
 
self.end = time.time()
 
 
def _duration(self):
 
if self.end:
 
return self.end - self.start
 
else:
 
return time.time() - self.start
 
 
def __repr__(self):
 
return f"{round(self._duration(), 2)}s"
 
 
def run(self):
 
self._start()
 
 
def stop(self, get_duration=False):
 
if self.end is None:
 
self._end()
 
else:
 
msg = f"Time was already stopped {time.time() - self.end}s ago."
 
logging.error(msg)
 
raise AssertionError(msg)
 
if get_duration:
 
return self.duration()
 
 
def duration(self):
 
return self._duration()
 
 
 
def prepare_host():
 
hostname = socket.gethostname()
 
user = os.getlogin()
 
if hostname == 'ZAM144':
 
path = f'/home/{user}/Data/toar_daily/'
 
elif hostname == 'zam347':
 
path = f'/home/{user}/Data/toar_daily/'
 
elif hostname == 'linux-gzsx':
 
path = f'/home/{user}/machinelearningtools'
 
elif (len(hostname) > 2) and (hostname[:2] == 'jr'):
 
path = f'/p/project/cjjsc42/{user}/DATA/toar_daily/'
 
elif (len(hostname) > 2) and (hostname[:2] == 'jw'):
 
path = f'/p/home/jusers/{user}/juwels/intelliaq/DATA/toar_daily/'
 
else:
 
logging.error(f"unknown host '{hostname}'")
 
raise OSError(f"unknown host '{hostname}'")
 
if not os.path.exists(path):
 
logging.error(f"path '{path}' does not exist for host '{hostname}'.")
 
raise NotADirectoryError(f"path '{path}' does not exist for host '{hostname}'.")
 
else:
 
logging.info(f"set path to: {path}")
 
return path
 
 
 
def set_experiment_name(experiment_date=None, experiment_path=None):
 
 
if experiment_date is None:
 
experiment_name = "TestExperiment"
 
else:
 
experiment_name = f"{experiment_date}_network/"
 
if experiment_path is None:
 
experiment_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", experiment_name))
 
else:
 
experiment_path = os.path.abspath(experiment_path)
 
return experiment_name, experiment_path
Loading