Unverified 提交 070af881 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Fix `yaml.safe_load()` ignore emoji errors (#5060)

上级 5afc9c25
...@@ -87,7 +87,7 @@ class Model(nn.Module): ...@@ -87,7 +87,7 @@ class Model(nn.Module):
else: # is *.yaml else: # is *.yaml
import yaml # for torch hub import yaml # for torch hub
self.yaml_file = Path(cfg).name self.yaml_file = Path(cfg).name
with open(cfg) as f: with open(cfg, errors='ignore') as f:
self.yaml = yaml.safe_load(f) # model dict self.yaml = yaml.safe_load(f) # model dict
# Define model # Define model
......
...@@ -72,7 +72,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary ...@@ -72,7 +72,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
# Hyperparameters # Hyperparameters
if isinstance(hyp, str): if isinstance(hyp, str):
with open(hyp) as f: with open(hyp, errors='ignore') as f:
hyp = yaml.safe_load(f) # load hyps dict hyp = yaml.safe_load(f) # load hyps dict
LOGGER.info(colorstr('hyperparameters: ') + ', '.join(f'{k}={v}' for k, v in hyp.items())) LOGGER.info(colorstr('hyperparameters: ') + ', '.join(f'{k}={v}' for k, v in hyp.items()))
...@@ -488,7 +488,7 @@ def main(opt, callbacks=Callbacks()): ...@@ -488,7 +488,7 @@ def main(opt, callbacks=Callbacks()):
if opt.resume and not check_wandb_resume(opt) and not opt.evolve: # resume an interrupted run if opt.resume and not check_wandb_resume(opt) and not opt.evolve: # resume an interrupted run
ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path
assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist' assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist'
with open(Path(ckpt).parent.parent / 'opt.yaml') as f: with open(Path(ckpt).parent.parent / 'opt.yaml', errors='ignore') as f:
opt = argparse.Namespace(**yaml.safe_load(f)) # replace opt = argparse.Namespace(**yaml.safe_load(f)) # replace
opt.cfg, opt.weights, opt.resume = '', ckpt, True # reinstate opt.cfg, opt.weights, opt.resume = '', ckpt, True # reinstate
LOGGER.info(f'Resuming training from {ckpt}') LOGGER.info(f'Resuming training from {ckpt}')
...@@ -552,7 +552,7 @@ def main(opt, callbacks=Callbacks()): ...@@ -552,7 +552,7 @@ def main(opt, callbacks=Callbacks()):
'mixup': (1, 0.0, 1.0), # image mixup (probability) 'mixup': (1, 0.0, 1.0), # image mixup (probability)
'copy_paste': (1, 0.0, 1.0)} # segment copy-paste (probability) 'copy_paste': (1, 0.0, 1.0)} # segment copy-paste (probability)
with open(opt.hyp) as f: with open(opt.hyp, errors='ignore') as f:
hyp = yaml.safe_load(f) # load hyps dict hyp = yaml.safe_load(f) # load hyps dict
if 'anchors' not in hyp: # anchors commented in hyp.yaml if 'anchors' not in hyp: # anchors commented in hyp.yaml
hyp['anchors'] = 3 hyp['anchors'] = 3
......
...@@ -21,7 +21,7 @@ for last in path.rglob('*/**/last.pt'): ...@@ -21,7 +21,7 @@ for last in path.rglob('*/**/last.pt'):
continue continue
# Load opt.yaml # Load opt.yaml
with open(last.parent.parent / 'opt.yaml') as f: with open(last.parent.parent / 'opt.yaml', errors='ignore') as f:
opt = yaml.safe_load(f) opt = yaml.safe_load(f)
# Get device count # Get device count
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论