glenn-jocher commited on
Commit
070af88
1 Parent(s): 5afc9c2

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

Browse files
Files changed (3) hide show
  1. models/yolo.py +1 -1
  2. train.py +3 -3
  3. utils/aws/resume.py +1 -1
models/yolo.py CHANGED
@@ -87,7 +87,7 @@ class Model(nn.Module):
87
  else: # is *.yaml
88
  import yaml # for torch hub
89
  self.yaml_file = Path(cfg).name
90
- with open(cfg) as f:
91
  self.yaml = yaml.safe_load(f) # model dict
92
 
93
  # Define model
 
87
  else: # is *.yaml
88
  import yaml # for torch hub
89
  self.yaml_file = Path(cfg).name
90
+ with open(cfg, errors='ignore') as f:
91
  self.yaml = yaml.safe_load(f) # model dict
92
 
93
  # Define model
train.py CHANGED
@@ -72,7 +72,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
72
 
73
  # Hyperparameters
74
  if isinstance(hyp, str):
75
- with open(hyp) as f:
76
  hyp = yaml.safe_load(f) # load hyps dict
77
  LOGGER.info(colorstr('hyperparameters: ') + ', '.join(f'{k}={v}' for k, v in hyp.items()))
78
 
@@ -488,7 +488,7 @@ def main(opt, callbacks=Callbacks()):
488
  if opt.resume and not check_wandb_resume(opt) and not opt.evolve: # resume an interrupted run
489
  ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path
490
  assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist'
491
- with open(Path(ckpt).parent.parent / 'opt.yaml') as f:
492
  opt = argparse.Namespace(**yaml.safe_load(f)) # replace
493
  opt.cfg, opt.weights, opt.resume = '', ckpt, True # reinstate
494
  LOGGER.info(f'Resuming training from {ckpt}')
@@ -552,7 +552,7 @@ def main(opt, callbacks=Callbacks()):
552
  'mixup': (1, 0.0, 1.0), # image mixup (probability)
553
  'copy_paste': (1, 0.0, 1.0)} # segment copy-paste (probability)
554
 
555
- with open(opt.hyp) as f:
556
  hyp = yaml.safe_load(f) # load hyps dict
557
  if 'anchors' not in hyp: # anchors commented in hyp.yaml
558
  hyp['anchors'] = 3
 
72
 
73
  # Hyperparameters
74
  if isinstance(hyp, str):
75
+ with open(hyp, errors='ignore') as f:
76
  hyp = yaml.safe_load(f) # load hyps dict
77
  LOGGER.info(colorstr('hyperparameters: ') + ', '.join(f'{k}={v}' for k, v in hyp.items()))
78
 
 
488
  if opt.resume and not check_wandb_resume(opt) and not opt.evolve: # resume an interrupted run
489
  ckpt = opt.resume if isinstance(opt.resume, str) else get_latest_run() # specified or most recent path
490
  assert os.path.isfile(ckpt), 'ERROR: --resume checkpoint does not exist'
491
+ with open(Path(ckpt).parent.parent / 'opt.yaml', errors='ignore') as f:
492
  opt = argparse.Namespace(**yaml.safe_load(f)) # replace
493
  opt.cfg, opt.weights, opt.resume = '', ckpt, True # reinstate
494
  LOGGER.info(f'Resuming training from {ckpt}')
 
552
  'mixup': (1, 0.0, 1.0), # image mixup (probability)
553
  'copy_paste': (1, 0.0, 1.0)} # segment copy-paste (probability)
554
 
555
+ with open(opt.hyp, errors='ignore') as f:
556
  hyp = yaml.safe_load(f) # load hyps dict
557
  if 'anchors' not in hyp: # anchors commented in hyp.yaml
558
  hyp['anchors'] = 3
utils/aws/resume.py CHANGED
@@ -21,7 +21,7 @@ for last in path.rglob('*/**/last.pt'):
21
  continue
22
 
23
  # Load opt.yaml
24
- with open(last.parent.parent / 'opt.yaml') as f:
25
  opt = yaml.safe_load(f)
26
 
27
  # Get device count
 
21
  continue
22
 
23
  # Load opt.yaml
24
+ with open(last.parent.parent / 'opt.yaml', errors='ignore') as f:
25
  opt = yaml.safe_load(f)
26
 
27
  # Get device count