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

pull/5088/head
Glenn Jocher 2021-10-05 13:41:52 -07:00 committed by GitHub
parent 5afc9c25ef
commit 070af88108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -87,7 +87,7 @@ class Model(nn.Module):
else: # is *.yaml
import yaml # for torch hub
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
# Define model

View File

@ -72,7 +72,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
# Hyperparameters
if isinstance(hyp, str):
with open(hyp) as f:
with open(hyp, errors='ignore') as f:
hyp = yaml.safe_load(f) # load hyps dict
LOGGER.info(colorstr('hyperparameters: ') + ', '.join(f'{k}={v}' for k, v in hyp.items()))
@ -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
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'
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.cfg, opt.weights, opt.resume = '', ckpt, True # reinstate
LOGGER.info(f'Resuming training from {ckpt}')
@ -552,7 +552,7 @@ def main(opt, callbacks=Callbacks()):
'mixup': (1, 0.0, 1.0), # image mixup (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
if 'anchors' not in hyp: # anchors commented in hyp.yaml
hyp['anchors'] = 3

View File

@ -21,7 +21,7 @@ for last in path.rglob('*/**/last.pt'):
continue
# 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)
# Get device count