Welcome to easycore’s documentation!¶
Tutorials¶
Installation¶
Requirements¶
- Python ≥ 3.6
Build easycore from Source¶
pip install 'git+https://github.com/YuxinZhaozyx/easycore.git'
# or build it from local
git clone https://github.com/YuxinZhaozyx/easycore.git
cd easycore
pip install -e .
Light weight config tools¶
easycore make it easy to load config from local yaml file, save config and control the config in runtime.
Load config from local yaml file¶
An example of yaml file is shown bellow:
MODEL:
IN_FEAUTRES: ["res3", "res4", "res5"]
INPUT_SIZE: (224, 224)
NUM_CLASSES: 100
NAME: YuxinZhaozyx
You can load the yaml file in the follow way:
from easycore.common.config import CfgNode as CN
cfg = CN.open('example.yaml')
# or
with open('example.yaml', 'r', encoding='utf-8') as f:
cfg = CN.open(f)
Get an empty config¶
cfg = CN()
Get a config from from python dict
¶
init_dict = {
"MODEL": {
"IN_FEATURES": ["res3", "res4", "res5"],
"INPUT_SIZE": (224, 224),
"NUM_CLASSES": 100,
},
"NAME": "YuxinZhaozyx",
}
cfg = CN(init_dict)
Use config¶
# get value from config
# the config has been automatically transform into python data type.
in_features = cfg.MODEL.IN_FEATURES # list
input_size = cfg.MODEL.INPUT_SIZE # tuple
num_classes = cfg.MODEL.NUM_CLASSES # int
name = cfg.NAME # str
# add new value to config
cfg.LICENSE = 'MIT'
# add a new CfgNode to config
cfg.SOLVER = CN()
cfg.SOLVER.LEARNING_RATE = 0.001
cfg.SOLVER.BATCH_SIZE = 128
Merge two config¶
cfg_a = CN()
cfg_a.key1 = 1
cfg_a.key2 = 2
cfg_b = CN()
cfg_b.key2 = 3
cfg_c.key3 = 4
# merge two config
cfg_a.merge(cfg_b) # now cfg_a.key2 is 3
Copy a config¶
cfg_copy = cfg.copy() # get a deepcopy of cfg
Save config to yaml file¶
cfg.save("example-save.yaml")
# or
with open("example-save.yaml", 'w', encoding='utf-8') as f:
cfg.save(f)
API Documentation¶
API Documentation¶
easycore.common¶
easycore.common.config¶
-
class
easycore.common.config.
CfgNode
(init_dict: dict = None, copy=True)[source]¶ Bases:
dict
Config Node
-
freeze
(frozen: bool = True)[source]¶ freeze or unfreeze the CfgNode and all of its children
Parameters: frozen (bool) – freeze or unfreeze the config
-
merge
(cfg)[source]¶ merge another CfgNode into this CfgNode, the another CfgNode will override this CfgNode.
Parameters: cfg (CfgNode) –
-
classmethod
open
(file, encoding='utf-8')[source]¶ load a CfgNode from file.
Parameters: Returns: CfgNode
-
classmethod
load
(yaml_str: str)[source]¶ load a CfgNode from a string of yaml format
Parameters: yaml_str (str) – Returns: CfgNode
-
classmethod
dump
(cfg, stream=None, encoding=None, **kwargs)[source]¶ dump CfgNode into yaml str or yaml file
Note
if stream option is set to non-None object, the CfgNode will be dumpped into stream and return None, if stream option is not given or set to None, return a string instead.
Parameters: - cfg (CfgNode) –
- stream (io.IOBase or None) – if set to a file object, the CfgNode will be dumpped into stream and return None, if set to None, return a string instead.
- encoding (str or None) –
- **kwargs –
options of the yaml dumper.
Some useful options: [“allow_unicode”, “line_break”, “explicit_start”, “explicit_end”, “version”, “tags”].
See more details at https://github.com/yaml/pyyaml/blob/2f463cf5b0e98a52bc20e348d1e69761bf263b86/lib3/yaml/__init__.py#L252
Returns: None or str
-