本文整理匯總了Python中yaml.FullLoader方法的典型用法代碼示例。如果您正苦於以下問題:Python yaml.FullLoader方法的具體用法?Python yaml.FullLoader怎麽用?Python yaml.FullLoader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yaml
的用法示例。
在下文中一共展示了yaml.FullLoader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: import_files
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def import_files(self):
print("self.manifest_path", self.manifest_path)
self.manifest = yaml.load(open("{}/manifest.yml".format(self.manifest_path)), Loader=yaml.FullLoader)
sys.path.append(self.manifest_path)
"""
don't remove the import below, this will be the cti_transformations.py,
which is one of the required file to run the job. This file will be provided by the
user during the run.
"""
try:
import ib_functions
except Exception as e:
ib_functions = None
self.ib_functions = ib_functions
print ("self.ib_functions is {}".format(ib_functions))
# print("manifest is {}".format(self.manifest))
# print("ib_functions is {}".format(self.ib_functions))
示例2: readYaml
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def readYaml(env=None):
"""Load the skelebot.yaml, with environment overrride if present, into the Config object"""
yamlData = None
cwd = os.getcwd()
cfgFile = FILE_PATH.format(path=cwd)
if os.path.isfile(cfgFile):
with open(cfgFile, 'r') as stream:
yamlData = yaml.load(stream, Loader=yaml.FullLoader)
if (env is not None):
envFile = ENV_FILE_PATH.format(path=cwd, env=env)
if os.path.isfile(envFile):
with open(envFile, 'r') as stream:
overrideYaml = yaml.load(stream, Loader=yaml.FullLoader)
yamlData = override(yamlData, overrideYaml)
else:
raise RuntimeError("Environment Not Found")
return yamlData
示例3: load_config
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def load_config(config_path):
""" Load a configuration file, also reading any component configs """
with open(str(config_path)) as config_fd:
config = yaml.load(config_fd, Loader=yaml.FullLoader)
for component in config:
if isinstance(config[component], dict) and "path" in config[component]:
component_path = CONFIG_ROOT / config[component]["path"]
with open(str(component_path)) as component_fd:
component_config = yaml.load(component_fd, Loader=yaml.FullLoader)
component_config.update(config[component])
config[component] = component_config
if "name" not in config[component]:
config[component]["name"] = component_path.stem
if "name" not in config:
config["name"] = config_path.stem
return config
示例4: generatetempyaml_multi
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def generatetempyaml_multi(yamlfile,videolist):
#copy yaml and rename
tempyaml = os.path.dirname(yamlfile) +'\\temp.yaml'
shutil.copy(yamlfile,tempyaml)
deeplabcut.add_new_videos(tempyaml,videolist,copy_videos=True)
with open(tempyaml) as f:
read_yaml = yaml.load(f, Loader=yaml.FullLoader)
original_videosets = read_yaml['video_sets'].keys()
keys=[]
for i in original_videosets:
keys.append(i)
read_yaml['video_sets'].pop(keys[0],None)
with open(tempyaml, 'w') as outfile:
yaml.dump(read_yaml, outfile, default_flow_style=False)
示例5: update_init_weight
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def update_init_weight(yamlfile,initweights):
yamlPath=yamlfile
initweights,initw_filetype = os.path.splitext(initweights)
with open(yamlPath) as f:
read_yaml = yaml.load(f, Loader=yaml.FullLoader)
iteration = read_yaml['iteration']
yamlfiledirectory = os.path.dirname(yamlfile)
iterationfolder = yamlfiledirectory +'\\dlc-models\\iteration-' +str(iteration)
projectfolder = os.listdir(iterationfolder)
projectfolder = projectfolder[0]
posecfg = iterationfolder + '\\' + projectfolder +'\\train\\' + 'pose_cfg.yaml'
with open(posecfg) as g:
read_cfg = yaml.load(g, Loader=yaml.FullLoader)
read_cfg['init_weights'] = str(initweights)
with open(posecfg, 'w') as outfile:
yaml.dump(read_cfg, outfile, default_flow_style=False)
print(os.path.basename(initweights),'selected')
示例6: add_single_video_yaml
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def add_single_video_yaml(yamlfile,videofile):
yamlPath = yamlfile
cap = cv2.VideoCapture(videofile)
width = int(cap.get(3)) # float
height = int(cap.get(4)) # float
cropLine = [0, width, 0, height]
cropLine = str(cropLine)
currCropLinePath = cropLine.strip("[]")
currCropLinePath = currCropLinePath.replace("'", "")
with open(yamlPath) as f:
read_yaml = yaml.load(f, Loader=yaml.FullLoader)
read_yaml["video_sets"].update({videofile: {'crop': currCropLinePath}})
with open(yamlPath, 'w') as outfile:
yaml.dump(read_yaml, outfile, default_flow_style=False)
示例7: load_configs_from_yaml
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def load_configs_from_yaml(yaml_file: str) -> Dict:
"""
從yaml配置文件中加載參數,這裏會將嵌套的二級映射調整為一級映射
Args:
yaml_file: yaml】文件路徑
Returns:
yaml文件中的配置字典
"""
yaml_config = yaml.load(open(yaml_file, encoding='utf-8'), Loader=yaml.FullLoader)
configs_dict = {}
for sub_k, sub_v in yaml_config.items():
# 讀取嵌套的參數
if isinstance(sub_v, dict):
for k, v in sub_v.items():
if k in configs_dict.keys():
raise ValueError(f'Duplicate parameter : {k}')
configs_dict[k] = v
else:
configs_dict[sub_k] = sub_v
return configs_dict
示例8: find_descriptor_schemas
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def find_descriptor_schemas(self, schema_file):
"""Find descriptor schemas in given path."""
if not schema_file.lower().endswith((".yml", ".yaml")):
return []
with open(schema_file) as fn:
schemas = yaml.load(fn, Loader=yaml.FullLoader)
if not schemas:
self.stderr.write("Could not read YAML file {}".format(schema_file))
return []
descriptor_schemas = []
for schema in schemas:
if "schema" not in schema:
continue
descriptor_schemas.append(schema)
return descriptor_schemas
示例9: test_improper_metrics_repo
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def test_improper_metrics_repo(improper_metrics_repo):
runner.main(cache_dir, out_dir, None, None, False, True, repositories_file,
True, None, None, None, None, 'dev')
path = os.path.join(out_dir, "glean", improper_repo_name, "metrics")
with open(path, 'r') as data:
metrics = json.load(data)
# should be empty output, since it was an improper file
assert not metrics
with open(EMAIL_FILE, 'r') as email_file:
emails = yaml.load(email_file, Loader=yaml.FullLoader)
# should send 1 email
assert len(emails) == 1
示例10: test_regularize_parameters
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def test_regularize_parameters():
params_yaml = """
params:
stop_cycle: 100
variant: [A, B, C]
probability: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
"""
params = yaml.load(params_yaml, Loader=yaml.FullLoader)
reg_params = regularize_parameters(params["params"])
assert len(reg_params) == 3
assert len(reg_params["stop_cycle"]) == 1
for v in reg_params["stop_cycle"]:
assert isinstance(v, str)
assert len(reg_params["variant"]) == 3
for v in reg_params["variant"]:
assert isinstance(v, str)
assert len(reg_params["probability"]) == 6
for v in reg_params["probability"]:
assert isinstance(v, str)
示例11: test_run_batches_direct_and_iteration
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def test_run_batches_direct_and_iteration(mock_run_batch):
with tempfile.TemporaryDirectory() as tmpdirname:
definition = f"""
sets:
set1:
path: {tmpdirname}
iterations: 3
batches:
batch1:
command: test
"""
conf = yaml.load(definition, Loader=yaml.FullLoader)
run_batches(conf, simulate=False)
assert mock_run_batch.call_count == 3
示例12: load_dcop
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def load_dcop(dcop_str: str, main_dir=None) -> DCOP:
loaded = yaml.load(dcop_str, Loader=yaml.FullLoader)
if "name" not in loaded:
raise ValueError("Missing name in dcop string")
if "objective" not in loaded or loaded["objective"] not in ["min", "max"]:
raise ValueError("Objective is mandatory and must be min or max")
dcop = DCOP(
loaded["name"],
loaded["objective"],
loaded["description"] if "description" in loaded else "",
)
dcop.domains = _build_domains(loaded)
dcop.variables = _build_variables(loaded, dcop)
dcop.external_variables = _build_external_variables(loaded, dcop)
dcop._constraints = _build_constraints(loaded, dcop, main_dir)
dcop._agents_def = _build_agents(loaded)
dcop.dist_hints = _build_dist_hints(loaded, dcop)
return dcop
示例13: load_scenario
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def load_scenario(scenario_str) -> Scenario:
"""
Load a scenario from a yaml string.
:param scenario_str:
:return:
"""
loaded = yaml.load(scenario_str, Loader=yaml.FullLoader)
evts = []
for evt in loaded["events"]:
id_evt = evt["id"]
if "actions" in evt:
actions = []
for a in evt["actions"]:
args = dict(a)
args.pop("type")
actions.append(EventAction(a["type"], **args))
evts.append(DcopEvent(id_evt, actions=actions))
elif "delay" in evt:
evts.append(DcopEvent(id_evt, delay=evt["delay"]))
return Scenario(evts)
示例14: load_config
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def load_config(yaml_file):
logger.debug("Loading configuration from %s" % yaml_file)
fd = None
try:
fd = open(yaml_file)
except Exception as e:
logger.error(
"Error reading configuration file %s, ignoring..." % yaml_file
)
return
try:
return yaml.load(fd, Loader=yaml.FullLoader)
except Exception as e:
logger.error(
"Error parsing configuration file %s: %s" % (yaml_file, e)
)
return
示例15: main
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import FullLoader [as 別名]
def main(args):
with open(args.config) as f:
if version.parse(yaml.version >= "5.1"):
config = yaml.load(f, Loader=yaml.FullLoader)
else:
config = yaml.load(f)
for k, v in config.items():
setattr(args, k, v)
# exp path
if not hasattr(args, 'exp_path'):
args.exp_path = os.path.dirname(args.config)
# dist init
if mp.get_start_method(allow_none=True) != 'spawn':
mp.set_start_method('spawn', force=True)
dist_init(args.launcher, backend='nccl')
# train
trainer = Trainer(args)
trainer.run()