Python core.config() Examples
The following are 30
code examples of core.config().
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
core
, or try the search function
.
Example #1
Source File: config_utils.py From deep-smoke-machine with BSD 3-Clause "New" or "Revised" License | 6 votes |
def cfg_merge_dicts(dict_a, dict_b): from ast import literal_eval for key, value in dict_a.items(): if key not in dict_b: raise KeyError('Invalid key in config file: {}'.format(key)) if type(value) is dict: dict_a[key] = value = AttrDict(value) if isinstance(value, str): try: value = literal_eval(value) except BaseException: pass # the types must match, too old_type = type(dict_b[key]) if old_type is not type(value) and value is not None: raise ValueError('Type mismatch ({} vs. {}) for config key: {}'.format(type(dict_b[key]), type(value), key)) # recursively merge dicts if isinstance(value, AttrDict): try: cfg_merge_dicts(dict_a[key], dict_b[key]) except BaseException: raise Exception('Error under config key: {}'.format(key)) else: dict_b[key] = value
Example #2
Source File: reval.py From NucleiDetectron with Apache License 2.0 | 6 votes |
def do_reval(dataset_name, output_dir, args): dataset = JsonDataset(dataset_name) with open(os.path.join(output_dir, 'detections.pkl'), 'rb') as f: dets = pickle.load(f) # Override config with the one saved in the detections file if args.cfg_file is not None: core.config.merge_cfg_from_cfg(yaml.load(dets['cfg'])) else: core.config._merge_a_into_b(yaml.load(dets['cfg']), cfg) results = task_evaluation.evaluate_all( dataset, dets['all_boxes'], dets['all_segms'], dets['all_keyps'], output_dir, use_matlab=args.matlab_eval ) task_evaluation.log_copy_paste_friendly_results(results)
Example #3
Source File: reval.py From masktextspotter.caffe2 with Apache License 2.0 | 6 votes |
def do_reval(dataset_name, output_dir, args): dataset = JsonDataset(dataset_name) with open(os.path.join(output_dir, 'detections.pkl'), 'rb') as f: dets = pickle.load(f) # Override config with the one saved in the detections file if args.cfg_file is not None: core.config.merge_cfg_from_cfg(yaml.load(dets['cfg'])) else: core.config._merge_a_into_b(yaml.load(dets['cfg']), cfg) results = task_evaluation.evaluate_all( dataset, dets['all_boxes'], dets['all_segms'], dets['all_keyps'], output_dir, use_matlab=args.matlab_eval ) task_evaluation.log_copy_paste_friendly_results(results)
Example #4
Source File: reval.py From seg_every_thing with Apache License 2.0 | 6 votes |
def do_reval(dataset_name, output_dir, args): dataset = JsonDataset(dataset_name) with open(os.path.join(output_dir, 'detections.pkl'), 'rb') as f: dets = pickle.load(f) # Override config with the one saved in the detections file if args.cfg_file is not None: core.config.merge_cfg_from_cfg(yaml.load(dets['cfg'])) else: core.config._merge_a_into_b(yaml.load(dets['cfg']), cfg) results = task_evaluation.evaluate_all( dataset, dets['all_boxes'], dets['all_segms'], dets['all_keyps'], output_dir, use_matlab=args.matlab_eval ) task_evaluation.log_copy_paste_friendly_results(results)
Example #5
Source File: config_utils.py From timeception with GNU General Public License v3.0 | 6 votes |
def cfg_from_list(args_list): """ Set config keys via list (e.g., from command line). """ from ast import literal_eval assert len(args_list) % 2 == 0, 'Specify values or keys for args' for key, value in zip(args_list[0::2], args_list[1::2]): key_list = key.split('.') cfg = __C for subkey in key_list[:-1]: assert subkey in cfg, 'Config key {} not found'.format(subkey) cfg = cfg[subkey] subkey = key_list[-1] assert subkey in cfg, 'Config key {} not found'.format(subkey) try: # handle the case when v is a string literal val = literal_eval(value) except BaseException: val = value msg = 'type {} does not match original type {}'.format(type(val), type(cfg[subkey])) assert isinstance(val, type(cfg[subkey])) or cfg[subkey] is None, msg cfg[subkey] = val
Example #6
Source File: config_utils.py From timeception with GNU General Public License v3.0 | 6 votes |
def cfg_merge_dicts(dict_a, dict_b): from ast import literal_eval for key, value in dict_a.items(): if key not in dict_b: raise KeyError('Invalid key in config file: {}'.format(key)) if type(value) is dict: dict_a[key] = value = AttrDict(value) if isinstance(value, str): try: value = literal_eval(value) except BaseException: pass # the types must match, too old_type = type(dict_b[key]) if old_type is not type(value) and value is not None: raise ValueError('Type mismatch ({} vs. {}) for config key: {}'.format(type(dict_b[key]), type(value), key)) # recursively merge dicts if isinstance(value, AttrDict): try: cfg_merge_dicts(dict_a[key], dict_b[key]) except BaseException: raise Exception('Error under config key: {}'.format(key)) else: dict_b[key] = value
Example #7
Source File: config_utils.py From deep-smoke-machine with BSD 3-Clause "New" or "Revised" License | 6 votes |
def cfg_from_dict(args_dict): """Set config keys via list (e.g., from command line).""" for key, value in args_dict.iteritems(): key_list = key.split('.') cfg = __C for subkey in key_list[:-1]: assert subkey in cfg, 'Config key {} not found'.format(subkey) cfg = cfg[subkey] subkey = key_list[-1] if subkey not in cfg: raise Exception('Config key {} not found'.format(subkey)) try: # handle the case when v is a string literal val = literal_eval(value) except BaseException: val = value if isinstance(val, type(cfg[subkey])) or cfg[subkey] is None: pass else: type1 = type(val) type2 = type(cfg[subkey]) msg = 'type {} does not match original type {}'.format(type1, type2) raise Exception(msg) cfg[subkey] = val
Example #8
Source File: config_utils.py From deep-smoke-machine with BSD 3-Clause "New" or "Revised" License | 6 votes |
def cfg_from_list(args_list): """ Set config keys via list (e.g., from command line). """ from ast import literal_eval assert len(args_list) % 2 == 0, 'Specify values or keys for args' for key, value in zip(args_list[0::2], args_list[1::2]): key_list = key.split('.') cfg = __C for subkey in key_list[:-1]: assert subkey in cfg, 'Config key {} not found'.format(subkey) cfg = cfg[subkey] subkey = key_list[-1] assert subkey in cfg, 'Config key {} not found'.format(subkey) try: # handle the case when v is a string literal val = literal_eval(value) except BaseException: val = value msg = 'type {} does not match original type {}'.format(type(val), type(cfg[subkey])) assert isinstance(val, type(cfg[subkey])) or cfg[subkey] is None, msg cfg[subkey] = val
Example #9
Source File: test_cfg.py From NucleiDetectron with Apache License 2.0 | 5 votes |
def test_deprecated_key_from_file(self): # You should see logger messages like: # "Deprecated config key (ignoring): MODEL.DILATION" with tempfile.NamedTemporaryFile() as f: cfg2 = copy.deepcopy(cfg) cfg2.MODEL.DILATION = 2 yaml.dump(cfg2, f) with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa core.config.merge_cfg_from_file(f.name) with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa
Example #10
Source File: test_cfg.py From masktextspotter.caffe2 with Apache License 2.0 | 5 votes |
def test_deprecated_key_from_list(self): # You should see logger messages like: # "Deprecated config key (ignoring): MODEL.DILATION" opts = ['FINAL_MSG', 'foobar', 'MODEL.DILATION', 2] with self.assertRaises(AttributeError): _ = cfg.FINAL_MSG # noqa with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa core.config.merge_cfg_from_list(opts) with self.assertRaises(AttributeError): _ = cfg.FINAL_MSG # noqa with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa
Example #11
Source File: test_cfg.py From masktextspotter.caffe2 with Apache License 2.0 | 5 votes |
def test_deprecated_key_from_file(self): # You should see logger messages like: # "Deprecated config key (ignoring): MODEL.DILATION" with tempfile.NamedTemporaryFile() as f: cfg2 = copy.deepcopy(cfg) cfg2.MODEL.DILATION = 2 yaml.dump(cfg2, f) with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa core.config.merge_cfg_from_file(f.name) with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa
Example #12
Source File: test_cfg.py From masktextspotter.caffe2 with Apache License 2.0 | 5 votes |
def test_renamed_key_from_file(self): # You should see logger messages like: # "Key EXAMPLE.RENAMED.KEY was renamed to EXAMPLE.KEY; # please update your config" with tempfile.NamedTemporaryFile() as f: cfg2 = copy.deepcopy(cfg) cfg2.EXAMPLE = AttrDict() cfg2.EXAMPLE.RENAMED = AttrDict() cfg2.EXAMPLE.RENAMED.KEY = 'foobar' yaml.dump(cfg2, f) with self.assertRaises(AttributeError): _ = cfg.EXAMPLE.RENAMED.KEY # noqa with self.assertRaises(KeyError): core.config.merge_cfg_from_file(f.name)
Example #13
Source File: reval.py From masktextspotter.caffe2 with Apache License 2.0 | 5 votes |
def parse_args(): parser = argparse.ArgumentParser(description='Re-evaluate results') parser.add_argument( 'output_dir', nargs=1, help='results directory', type=str ) parser.add_argument( '--dataset', dest='dataset_name', help='dataset to re-evaluate', default='voc_2007_test', type=str ) parser.add_argument( '--matlab', dest='matlab_eval', help='use matlab for evaluation', action='store_true' ) parser.add_argument( '--comp', dest='comp_mode', help='competition mode', action='store_true' ) parser.add_argument( '--cfg', dest='cfg_file', help='optional config file', default=None, type=str ) if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() return args
Example #14
Source File: config_utils.py From deep-smoke-machine with BSD 3-Clause "New" or "Revised" License | 5 votes |
def cfg_from_file(file_path, is_check=True): """ Load a config file and merge it into the default options. """ # read from file yaml_config = utils.yaml_load(file_path) # merge to project config cfg_merge_dicts(yaml_config, __C) # make sure everything is okay if is_check: cfg_sanity_check()
Example #15
Source File: test_cfg.py From NucleiDetectron with Apache License 2.0 | 5 votes |
def test_merge_cfg_from_file(self): with tempfile.NamedTemporaryFile() as f: yaml.dump(cfg, f) s = cfg.MODEL.TYPE cfg.MODEL.TYPE = 'dummy' assert cfg.MODEL.TYPE != s core.config.merge_cfg_from_file(f.name) assert cfg.MODEL.TYPE == s
Example #16
Source File: test_cfg.py From NucleiDetectron with Apache License 2.0 | 5 votes |
def test_merge_cfg_from_list(self): opts = [ 'TRAIN.SCALES', '(100, )', 'MODEL.TYPE', u'foobar', 'NUM_GPUS', 2 ] assert len(cfg.TRAIN.SCALES) > 0 assert cfg.TRAIN.SCALES[0] != 100 assert cfg.MODEL.TYPE != 'foobar' assert cfg.NUM_GPUS != 2 core.config.merge_cfg_from_list(opts) assert type(cfg.TRAIN.SCALES) is tuple assert len(cfg.TRAIN.SCALES) == 1 assert cfg.TRAIN.SCALES[0] == 100 assert cfg.MODEL.TYPE == 'foobar' assert cfg.NUM_GPUS == 2
Example #17
Source File: test_cfg.py From NucleiDetectron with Apache License 2.0 | 5 votes |
def test_deprecated_key_from_list(self): # You should see logger messages like: # "Deprecated config key (ignoring): MODEL.DILATION" opts = ['FINAL_MSG', 'foobar', 'MODEL.DILATION', 2] with self.assertRaises(AttributeError): _ = cfg.FINAL_MSG # noqa with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa core.config.merge_cfg_from_list(opts) with self.assertRaises(AttributeError): _ = cfg.FINAL_MSG # noqa with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa
Example #18
Source File: test_cfg.py From masktextspotter.caffe2 with Apache License 2.0 | 5 votes |
def test_merge_cfg_from_list(self): opts = [ 'TRAIN.SCALES', '(100, )', 'MODEL.TYPE', u'foobar', 'NUM_GPUS', 2 ] assert len(cfg.TRAIN.SCALES) > 0 assert cfg.TRAIN.SCALES[0] != 100 assert cfg.MODEL.TYPE != 'foobar' assert cfg.NUM_GPUS != 2 core.config.merge_cfg_from_list(opts) assert type(cfg.TRAIN.SCALES) is tuple assert len(cfg.TRAIN.SCALES) == 1 assert cfg.TRAIN.SCALES[0] == 100 assert cfg.MODEL.TYPE == 'foobar' assert cfg.NUM_GPUS == 2
Example #19
Source File: test_cfg.py From NucleiDetectron with Apache License 2.0 | 5 votes |
def test_renamed_key_from_file(self): # You should see logger messages like: # "Key EXAMPLE.RENAMED.KEY was renamed to EXAMPLE.KEY; # please update your config" with tempfile.NamedTemporaryFile() as f: cfg2 = copy.deepcopy(cfg) cfg2.EXAMPLE = AttrDict() cfg2.EXAMPLE.RENAMED = AttrDict() cfg2.EXAMPLE.RENAMED.KEY = 'foobar' yaml.dump(cfg2, f) with self.assertRaises(AttributeError): _ = cfg.EXAMPLE.RENAMED.KEY # noqa with self.assertRaises(KeyError): core.config.merge_cfg_from_file(f.name)
Example #20
Source File: reval.py From NucleiDetectron with Apache License 2.0 | 5 votes |
def parse_args(): parser = argparse.ArgumentParser(description='Re-evaluate results') parser.add_argument( 'output_dir', nargs=1, help='results directory', type=str ) parser.add_argument( '--dataset', dest='dataset_name', help='dataset to re-evaluate', default='voc_2007_test', type=str ) parser.add_argument( '--matlab', dest='matlab_eval', help='use matlab for evaluation', action='store_true' ) parser.add_argument( '--comp', dest='comp_mode', help='competition mode', action='store_true' ) parser.add_argument( '--cfg', dest='cfg_file', help='optional config file', default=None, type=str ) if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() return args
Example #21
Source File: config_utils.py From deep-smoke-machine with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __config_gpu_for_keras(): import tensorflow as tf import keras.backend as K gpu_core_id = __parse_gpu_id() K.clear_session() config = tf.ConfigProto() config.gpu_options.visible_device_list = str(gpu_core_id) config.gpu_options.allow_growth = True session = tf.Session(config=config) K.set_session(session) # set which device to be used const.GPU_CORE_ID = gpu_core_id
Example #22
Source File: test_cfg.py From DetectAndTrack with Apache License 2.0 | 5 votes |
def test_merge_cfg_from_file(self): with tempfile.NamedTemporaryFile() as f: yaml.dump(cfg, f) s = cfg.MODEL.TYPE cfg.MODEL.TYPE = 'dummy' assert cfg.MODEL.TYPE != s core.config.merge_cfg_from_file(f.name) assert cfg.MODEL.TYPE == s
Example #23
Source File: test_cfg.py From DetectAndTrack with Apache License 2.0 | 5 votes |
def test_merge_cfg_from_list(self): opts = [ 'TRAIN.SCALES', '(100, )', 'MODEL.TYPE', u'foobar', 'NUM_GPUS', 2 ] assert len(cfg.TRAIN.SCALES) > 0 assert cfg.TRAIN.SCALES[0] != 100 assert cfg.MODEL.TYPE != 'foobar' assert cfg.NUM_GPUS != 2 core.config.merge_cfg_from_list(opts) assert type(cfg.TRAIN.SCALES) is tuple assert len(cfg.TRAIN.SCALES) == 1 assert cfg.TRAIN.SCALES[0] == 100 assert cfg.MODEL.TYPE == 'foobar' assert cfg.NUM_GPUS == 2
Example #24
Source File: test_cfg.py From DetectAndTrack with Apache License 2.0 | 5 votes |
def test_deprecated_key_from_list(self): # You should see logger messages like: # "Deprecated config key (ignoring): MODEL.DILATION" opts = ['FINAL_MSG', 'foobar', 'MODEL.DILATION', 2] with self.assertRaises(AttributeError): _ = cfg.FINAL_MSG # noqa with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa core.config.merge_cfg_from_list(opts) with self.assertRaises(AttributeError): _ = cfg.FINAL_MSG # noqa with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa
Example #25
Source File: test_cfg.py From DetectAndTrack with Apache License 2.0 | 5 votes |
def test_deprecated_key_from_file(self): # You should see logger messages like: # "Deprecated config key (ignoring): MODEL.DILATION" with tempfile.NamedTemporaryFile() as f: cfg2 = copy.deepcopy(cfg) cfg2.MODEL.DILATION = 2 yaml.dump(cfg2, f) with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa core.config.merge_cfg_from_file(f.name) with self.assertRaises(AttributeError): _ = cfg.MODEL.DILATION # noqa
Example #26
Source File: test_cfg.py From DetectAndTrack with Apache License 2.0 | 5 votes |
def test_renamed_key_from_file(self): # You should see logger messages like: # "Key EXAMPLE.RENAMED.KEY was renamed to EXAMPLE.KEY; # please update your config" with tempfile.NamedTemporaryFile() as f: cfg2 = copy.deepcopy(cfg) cfg2.EXAMPLE = AttrDict() cfg2.EXAMPLE.RENAMED = AttrDict() cfg2.EXAMPLE.RENAMED.KEY = 'foobar' yaml.dump(cfg2, f) with self.assertRaises(AttributeError): _ = cfg.EXAMPLE.RENAMED.KEY # noqa with self.assertRaises(KeyError): core.config.merge_cfg_from_file(f.name)
Example #27
Source File: test_cfg.py From masktextspotter.caffe2 with Apache License 2.0 | 5 votes |
def test_merge_cfg_from_file(self): with tempfile.NamedTemporaryFile() as f: yaml.dump(cfg, f) s = cfg.MODEL.TYPE cfg.MODEL.TYPE = 'dummy' assert cfg.MODEL.TYPE != s core.config.merge_cfg_from_file(f.name) assert cfg.MODEL.TYPE == s
Example #28
Source File: train_pytorch.py From timeception with GNU General Public License v3.0 | 5 votes |
def __init__(self): super(Model, self).__init__() # some configurations for the model n_tc_timesteps = config.cfg.MODEL.N_TC_TIMESTEPS backbone_name = config.cfg.MODEL.BACKBONE_CNN feature_name = config.cfg.MODEL.BACKBONE_FEATURE n_tc_layers = config.cfg.MODEL.N_TC_LAYERS n_classes = config.cfg.MODEL.N_CLASSES is_dilated = config.cfg.MODEL.MULTISCALE_TYPE OutputActivation = Sigmoid if config.cfg.MODEL.CLASSIFICATION_TYPE == 'ml' else LogSoftmax n_channels_in, channel_h, channel_w = utils.get_model_feat_maps_info(backbone_name, feature_name) n_groups = int(n_channels_in / 128.0) input_shape = (None, n_channels_in, n_tc_timesteps, channel_h, channel_w) # (C, T, H, W) self._input_shape = input_shape # define 4 layers of timeception self.timeception = timeception_pytorch.Timeception(input_shape, n_tc_layers, n_groups, is_dilated) # (C, T, H, W) # get number of output channels after timeception n_channels_in = self.timeception.n_channels_out # define layers for classifier self.do1 = Dropout(0.5) self.l1 = Linear(n_channels_in, 512) self.bn1 = BatchNorm1d(512) self.ac1 = LeakyReLU(0.2) self.do2 = Dropout(0.25) self.l2 = Linear(512, n_classes) self.ac2 = OutputActivation()
Example #29
Source File: train_pytorch.py From timeception with GNU General Public License v3.0 | 5 votes |
def __main(): """ Run this script to train Timeception. """ default_config_file = 'charades_i3d_tc4_f1024.yaml' default_config_file = 'charades_i3d_tc2_f256.yaml' # Parse the arguments parser = OptionParser() parser.add_option('-c', '--config_file', dest='config_file', default=default_config_file, help='Yaml config file that contains all training details.') (options, args) = parser.parse_args() config_file = options.config_file # check if exist if config_file is None or config_file == '': msg = 'Config file not passed, default config is used: %s' % (config_file) logging.warning(msg) config_file = default_config_file # path of config file config_path = './configs/%s' % (config_file) # check if file exist if not os.path.exists(config_path): msg = 'Sorry, could not find config file with the following path: %s' % (config_path) logging.error(msg) else: # read the config from file and copy it to the project configuration "cfg" config_utils.cfg_from_file(config_path) # choose which training scheme, either 'ete' or 'tco' training_scheme = config.cfg.TRAIN.SCHEME # start training if training_scheme == 'tco': train_tco() else: train_ete()
Example #30
Source File: train_keras.py From timeception with GNU General Public License v3.0 | 5 votes |
def train_tco(): """ Train Timeception layers based on the given configurations. This train scheme is Timeception-only (TCO). """ # get some configs for the training n_workers = config.cfg.TRAIN.N_WORKERS n_epochs = config.cfg.TRAIN.N_EPOCHS dataset_name = config.cfg.DATASET_NAME model_name = '%s_%s' % (config.cfg.MODEL.NAME, utils.timestamp()) # data generators data_generator_tr = __define_data_generator(is_training=True) data_generator_te = __define_data_generator(is_training=False) logger.info('--- start time') logger.info(datetime.datetime.now()) logger.info('... [tr]: n_samples, n_batch, batch_size: %d, %d, %d' % (data_generator_tr.n_samples, data_generator_tr.n_batches, config.cfg.TRAIN.BATCH_SIZE)) logger.info('... [te]: n_samples, n_batch, batch_size: %d, %d, %d' % (data_generator_te.n_samples, data_generator_te.n_batches, config.cfg.TEST.BATCH_SIZE)) # callback to save the model save_callback = keras_utils.SaveCallback(dataset_name, model_name) # load model model = __define_timeception_model() logger.info(model.summary()) # train the model model.fit_generator(epochs=n_epochs, generator=data_generator_tr, validation_data=data_generator_te, use_multiprocessing=True, workers=n_workers, callbacks=[save_callback], verbose=2) logger.info('--- finish time') logger.info(datetime.datetime.now())