def cfg_from_file(file_name, target=__C): """ Load a config file and merge it into the default options. """ import yaml with open(file_name, 'r') as f: print('Loading YAML config file from %s' % f) yaml_cfg = edict(yaml.load(f)) _merge_two_config(yaml_cfg, target)
import numpy as np import os import yaml import logging from collections import OrderedDict from nowcasting.helpers.ordered_easydict import OrderedEasyDict as edict C = edict() cfg = C # type: edict() # Random seed C.MOVINGMNIST = edict() C.MOVINGMNIST.DIGIT_NUM = 3
def save_movingmnist_cfg(dir_path): tmp_cfg = edict() tmp_cfg.MOVINGMNIST = cfg.MOVINGMNIST tmp_cfg.MODEL = cfg.MODEL save_cfg(dir_path=dir_path, source=tmp_cfg)
from nowcasting.helpers.ordered_easydict import OrderedEasyDict as edict import numpy as np import os import torch __C = edict() cfg = __C __C.GLOBAL = edict() __C.GLOBAL.DEVICE = torch.device( "cuda" if torch.cuda.is_available() else "cpu") __C.GLOBAL.BATCH_SZIE = 2 for dirs in ['/home/hzzone/save', '/Users/hzzone/Downloads']: if os.path.exists(dirs): __C.GLOBAL.MODEL_SAVE_DIR = dirs assert __C.GLOBAL.MODEL_SAVE_DIR is not None __C.ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) __C.HKO_DATA_BASE_PATH = os.path.join(__C.ROOT_DIR, 'hko_data') for dirs in [ '/Users/hzzone/Downloads/HKO-7_data/radarPNG', '/home/hzzone/HKO-7/radarPNG' ]: if os.path.exists(dirs): __C.HKO_PNG_PATH = dirs for dirs in [ '/Users/hzzone/Downloads/HKO-7_data/radarPNG_mask', '/home/hzzone/HKO-7/radarPNG_mask' ]: if os.path.exists(dirs): __C.HKO_MASK_PATH = dirs
import numpy as np import os import yaml import logging from collections import OrderedDict from nowcasting.helpers.ordered_easydict import OrderedEasyDict as edict __C = edict() cfg = __C # type: edict() # Random seed __C.SEED = None # Dataset name # Used by symbols factories who need to adjust for different # inputs based on dataset used. Should be set by the script. __C.DATASET = None # Project directory, since config.py is supposed to be in $ROOT_DIR/nowcasting __C.ROOT_DIR = os.path.abspath('/content/lstmnowcast') __C.MNIST_PATH = os.path.join(__C.ROOT_DIR, 'mnist_data') if not os.path.exists(__C.MNIST_PATH): os.makedirs(__C.MNIST_PATH) __C.HKO_DATA_BASE_PATH = os.path.join(__C.ROOT_DIR, 'hko_data') # Append your path to the possible paths # possible_hko_png_paths = [os.path.join('E:\\datasets\\HKO-data\\radarPNG\\radarPNG'), # os.path.join(__C.HKO_DATA_BASE_PATH, 'radarPNG')] # possible_hko_mask_paths = [os.path.join('E:\\datasets\\HKO-data\\radarPNG\\radarPNG_mask'), # os.path.join(__C.HKO_DATA_BASE_PATH, 'radarPNG_mask')]
'memory.free', 'memory.used', 'utilization.gpu', 'utilization.memory' ) def get_gpu_info(nvidia_smi_path='nvidia-smi', keys=DEFAULT_ATTRIBUTES, no_units=True): nu_opt = '' if not no_units else ',nounits' cmd = '%s --query-gpu=%s --format=csv,noheader%s' % (nvidia_smi_path, ','.join(keys), nu_opt) output = subprocess.check_output(cmd, shell=True) lines = output.decode().split('\n') lines = [ line.strip() for line in lines if line.strip() != '' ] return [ { k: v for k, v in zip(keys, line.split(', ')) } for line in lines ] __C = edict() cfg = __C __C.GLOBAL = edict() __C.GLOBAL.DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu") if __C.GLOBAL.DEVICE.type == 'cuda': gpu_info = get_gpu_info() memory_use = np.array(list(map(int, [info['utilization.gpu'] for info in gpu_info]))) __C.GLOBAL.DEVICE = torch.device("cuda:%i" % (memory_use.argmin()) if torch.cuda.is_available() else "cpu") __C.GLOBAL.BATCH_SZIE = 2 # for dirs in ['/home/hzzone/save', '/Users/hzzone/Downloads']: # if os.path.exists(dirs): # __C.GLOBAL.MODEL_SAVE_DIR = dirs # assert __C.GLOBAL.MODEL_SAVE_DIR is not None __C.ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
def save_icdm_cfg(dir_path): tmp_cfg = edict() tmp_cfg.ICDM = cfg.ICDM tmp_cfg.MODEL = cfg.MODEL save_cfg(dir_path=dir_path, source=tmp_cfg)
from nowcasting.helpers.ordered_easydict import OrderedEasyDict as edict import numpy as np import os import torch __C = edict() cfg = __C __C.GLOBAL = edict() __C.GLOBAL.DEVICE = torch.device( "cuda" if torch.cuda.is_available() else "cpu") __C.GLOBAL.BATCH_SZIE = 10 for dirs in ['/home/s1818503/dissertation/save', '/Users/hzzone/Downloads']: if os.path.exists(dirs): __C.GLOBAL.MODEL_SAVE_DIR = dirs assert __C.GLOBAL.MODEL_SAVE_DIR is not None __C.ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) # __C.HKO_DATA_BASE_PATH = os.path.join(__C.ROOT_DIR, 'hko_data') # for dirs in ['/Users/hzzone/Downloads/HKO-7_data/radarPNG', '/home/hzzone/HKO-7/radarPNG']: # if os.path.exists(dirs): # __C.HKO_PNG_PATH = dirs # for dirs in ['/Users/hzzone/Downloads/HKO-7_data/radarPNG_mask', '/home/hzzone/HKO-7/radarPNG_mask']: # if os.path.exists(dirs): # __C.HKO_MASK_PATH = dirs __C.HKO = edict() __C.HKO.EVALUATION = edict() __C.HKO.EVALUATION.THRESHOLDS = np.array([0.5, 2, 5, 10, 30]) __C.HKO.EVALUATION.CENTRAL_REGION = (120, 120, 360, 360)