Python easydict.EasyDict() Examples
The following are 30
code examples of easydict.EasyDict().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
easydict
, or try the search function
.
Example #1
Source File: config.py From Pytorch-Project-Template with MIT License | 7 votes |
def get_config_from_json(json_file): """ Get the config from a json file :param json_file: the path of the config file :return: config(namespace), config(dictionary) """ # parse the configurations from the config json file provided with open(json_file, 'r') as config_file: try: config_dict = json.load(config_file) # EasyDict allows to access dict values as attributes (works recursively). config = EasyDict(config_dict) return config, config_dict except ValueError: print("INVALID JSON file format.. Please provide a good json file") exit(-1)
Example #2
Source File: face_image.py From insightface with MIT License | 6 votes |
def get_dataset_celeb(input_dir): clean_list_file = input_dir+"_clean_list.txt" ret = [] dir2label = {} for line in open(clean_list_file, 'r'): line = line.strip() if not line.startswith('./m.'): continue line = line[2:] vec = line.split('/') assert len(vec)==2 if vec[0] in dir2label: label = dir2label[vec[0]] else: label = len(dir2label) dir2label[vec[0]] = label fimage = edict() fimage.id = line fimage.classname = str(label) fimage.image_path = os.path.join(input_dir, fimage.id) ret.append(fimage) return ret
Example #3
Source File: dff_config.py From Deep-Feature-Flow-Segmentation with MIT License | 6 votes |
def update_config(config_file): exp_config = None with open(config_file) as f: exp_config = edict(yaml.load(f)) for k, v in exp_config.items(): if k in config: if isinstance(v, dict): if k == 'TRAIN': if 'BBOX_WEIGHTS' in v: v['BBOX_WEIGHTS'] = np.array(v['BBOX_WEIGHTS']) elif k == 'network': if 'PIXEL_MEANS' in v: v['PIXEL_MEANS'] = np.array(v['PIXEL_MEANS']) for vk, vv in v.items(): config[k][vk] = vv else: if k == 'SCALES': config[k][0] = (tuple(v)) else: config[k] = v else: raise ValueError("key must exist in config.py")
Example #4
Source File: config.py From Deep-Feature-Flow-Segmentation with MIT License | 6 votes |
def update_config(config_file): exp_config = None with open(config_file) as f: exp_config = edict(yaml.load(f)) for k, v in exp_config.items(): if k in config: if isinstance(v, dict): if k == 'TRAIN': if 'BBOX_WEIGHTS' in v: v['BBOX_WEIGHTS'] = np.array(v['BBOX_WEIGHTS']) elif k == 'network': if 'PIXEL_MEANS' in v: v['PIXEL_MEANS'] = np.array(v['PIXEL_MEANS']) for vk, vv in v.items(): config[k][vk] = vv else: if k == 'SCALES': config[k][0] = (tuple(v)) else: config[k] = v else: raise ValueError("key must exist in config.py")
Example #5
Source File: face_image.py From insightface with MIT License | 6 votes |
def get_dataset_facescrub(input_dir): ret = [] label = 0 person_names = [] for person_name in os.listdir(input_dir): person_names.append(person_name) person_names = sorted(person_names) for person_name in person_names: subdir = os.path.join(input_dir, person_name) if not os.path.isdir(subdir): continue for _img in os.listdir(subdir): fimage = edict() fimage.id = os.path.join(person_name, _img) fimage.classname = str(label) fimage.image_path = os.path.join(subdir, _img) fimage.landmark = None fimage.bbox = None ret.append(fimage) label += 1 return ret
Example #6
Source File: config.py From self-supervised-da with MIT License | 6 votes |
def get_config_from_yaml(yaml_file): """ Get the config from yaml file Input: - yaml_file: yaml configuration file Return: - config: namespace - config_dict: dictionary """ with open(yaml_file) as fp: config_dict = yaml.load(fp) # convert the dictionary to a namespace using bunch lib config = EasyDict(config_dict) return config, config_dict
Example #7
Source File: config.py From self-supervised-da with MIT License | 6 votes |
def get_config_from_json(json_file): """ Get the config from a json file Input: - json_file: json configuration file Return: - config: namespace - config_dict: dictionary """ # parse the configurations from the config json file provided with open(json_file, 'r') as config_file: config_dict = json.load(config_file) # convert the dictionary to a namespace using bunch lib config = EasyDict(config_dict) return config, config_dict
Example #8
Source File: arg_helper.py From LanczosNetwork with MIT License | 6 votes |
def get_config(config_file, exp_dir=None): """ Construct and snapshot hyper parameters """ config = edict(yaml.load(open(config_file, 'r'))) # create hyper parameters config.run_id = str(os.getpid()) config.exp_name = '_'.join([ config.model.name, config.dataset.name, time.strftime('%Y-%b-%d-%H-%M-%S'), config.run_id ]) if exp_dir is not None: config.exp_dir = exp_dir config.save_dir = os.path.join(config.exp_dir, config.exp_name) # snapshot hyperparameters mkdir(config.exp_dir) mkdir(config.save_dir) save_name = os.path.join(config.save_dir, 'config.yaml') yaml.dump(edict2dict(config), open(save_name, 'w'), default_flow_style=False) return config
Example #9
Source File: config.py From RetinaNet with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.iteritems(): # a must specify keys that are in b if not b.has_key(k): raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print('Error under config key: {}'.format(k)) raise else: b[k] = v
Example #10
Source File: config.py From tf_ctpn with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.items(): # a must specify keys that are in b if k not in b: raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print(('Error under config key: {}'.format(k))) raise else: b[k] = v
Example #11
Source File: config.py From tf_ctpn with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #12
Source File: utils.py From MobileNet with Apache License 2.0 | 5 votes |
def parse_args(): """ Parse the arguments of the program :return: (config_args) :rtype: tuple """ # Create a parser parser = argparse.ArgumentParser(description="MobileNet TensorFlow Implementation") parser.add_argument('--version', action='version', version='%(prog)s 1.0.0') parser.add_argument('--config', default=None, type=str, help='Configuration file') # Parse the arguments args = parser.parse_args() # Parse the configurations from the config json file provided try: if args.config is not None: with open(args.config, 'r') as config_file: config_args_dict = json.load(config_file) else: print("Add a config file using \'--config file_name.json\'", file=sys.stderr) exit(1) except FileNotFoundError: print("ERROR: Config file not found: {}".format(args.config), file=sys.stderr) exit(1) except json.decoder.JSONDecodeError: print("ERROR: Config file is not a proper JSON file!", file=sys.stderr) exit(1) config_args = edict(config_args_dict) pprint(config_args) print("\n") return config_args
Example #13
Source File: config.py From EasyPR-python with Apache License 2.0 | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.items(): # a must specify keys that are in b if k not in b: raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print('Error under config key: {}'.format(k)) raise else: b[k] = v
Example #14
Source File: config.py From EasyPR-python with Apache License 2.0 | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #15
Source File: config.py From DM-GAN with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.iteritems(): # a must specify keys that are in b if not b.has_key(k): raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print('Error under config key: {}'.format(k)) raise else: b[k] = v
Example #16
Source File: create_config.py From squeezedet-keras with MIT License | 5 votes |
def load_dict(path): """Loads a dictionary from a given path name Arguments: path {[type]} -- string of path Returns: [type] -- [description] """ with open(path, "r") as f: cfg = json.load(f) ### this loads the array from .json format #changes lists back for key, val, in cfg.items(): if type(val) is list: cfg[key] = np.array(val) #cast do easydict cfg = edict(cfg) #create full anchors from seed cfg.ANCHOR_BOX, cfg.N_ANCHORS_HEIGHT, cfg.N_ANCHORS_WIDTH = set_anchors(cfg) cfg.ANCHORS = len(cfg.ANCHOR_BOX) #if you added a class in the config manually, but were to lazy to update cfg.CLASSES = len(cfg.CLASS_NAMES) cfg.CLASS_TO_IDX = dict(zip(cfg.CLASS_NAMES, range(cfg.CLASSES))) return cfg #compute the anchors for the grid from the seed
Example #17
Source File: config.py From DM-GAN with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #18
Source File: config.py From StackGAN-Pytorch with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #19
Source File: config.py From SSH-TensorFlow with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #20
Source File: config.py From SSH-TensorFlow with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.items(): # a must specify keys that are in b if k not in b: raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print(('Error under config key: {}'.format(k))) raise else: b[k] = v
Example #21
Source File: model_evaluation.py From Face-and-Image-super-resolution with MIT License | 5 votes |
def main(): torch.manual_seed(1) np.random.seed(0) torch.cuda.manual_seed(1) torch.cuda.manual_seed_all(1) opt = edict() opt.nGPU = 1 opt.batchsize = 1 opt.cuda = True cudnn.benchmark = True print('========================LOAD DATA============================') data_name = 'widerfacetest' test_loader = get_loader(data_name, opt.batchsize) net_G_low2high = GEN_DEEP() net_G_low2high = net_G_low2high.cuda() a = torch.load('model.pkl') net_G_low2high.load_state_dict(a) net_G_low2high = net_G_low2high.eval() index = 0 test_file = 'test_res' if not os.path.exists(test_file): os.makedirs(test_file) for idx, data_dict in enumerate(test_loader): print(idx) index = index + 1 data_low = data_dict['img16'] data_high = data_dict['img64'] img_name = data_dict['imgpath'][0].split('/')[-1] data_input_low, batchsize_high = to_var(data_low) data_input_high, _ = to_var(data_high) data_high_output = net_G_low2high(data_input_low) path = os.path.join(test_file, img_name.split('.')[0]+'.jpg') vutils.save_image(data_high_output.data, path, normalize=True)
Example #22
Source File: config.py From cntk-python-web-service-on-azure with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #23
Source File: config.py From cntk-python-web-service-on-azure with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.iteritems(): # a must specify keys that are in b if not b.has_key(k): raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print('Error under config key: {}'.format(k)) raise else: b[k] = v
Example #24
Source File: default_config.py From cntk-python-web-service-on-azure with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #25
Source File: default_config.py From cntk-python-web-service-on-azure with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.iteritems(): # a must specify keys that are in b if not b.has_key(k): raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print('Error under config key: {}'.format(k)) raise else: b[k] = v
Example #26
Source File: config.py From LRP with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #27
Source File: config.py From LRP with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.items(): # a must specify keys that are in b if k not in b: raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print(('Error under config key: {}'.format(k))) raise else: b[k] = v
Example #28
Source File: config.py From pytorch-FPN with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)
Example #29
Source File: config.py From pytorch-FPN with MIT License | 5 votes |
def _merge_a_into_b(a, b): """Merge config dictionary a into config dictionary b, clobbering the options in b whenever they are also specified in a. """ if type(a) is not edict: return for k, v in a.items(): # a must specify keys that are in b if k not in b: raise KeyError('{} is not a valid config key'.format(k)) # the types must match, too old_type = type(b[k]) if old_type is not type(v): if isinstance(b[k], np.ndarray): v = np.array(v, dtype=b[k].dtype) else: raise ValueError(('Type mismatch ({} vs. {}) ' 'for config key: {}').format(type(b[k]), type(v), k)) # recursively merge dicts if type(v) is edict: try: _merge_a_into_b(a[k], b[k]) except: print(('Error under config key: {}'.format(k))) raise else: b[k] = v
Example #30
Source File: config.py From Collaborative-Learning-for-Weakly-Supervised-Object-Detection with MIT License | 5 votes |
def cfg_from_file(filename): """Load a config file and merge it into the default options.""" import yaml with open(filename, 'r') as f: yaml_cfg = edict(yaml.load(f)) _merge_a_into_b(yaml_cfg, __C)