From 480a429f5a1e70f7d86535cc701992b070e3c072 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 6 Nov 2021 16:03:14 +0100 Subject: [PATCH] Fix for *.yaml emojis on load (#5543) Fix for Colab hub error: ```python import yaml with open('yolov5s.yaml', errors='ignore') as f: d = yaml.safe_load(f) # model dict print(d) --------------------------------------------------------------------------- ReaderError Traceback (most recent call last) in () 2 3 with open('yolov5s.yaml', errors='ignore') as f: ----> 4 d = yaml.safe_load(f) # model dict 5 6 print(d) 6 frames /usr/local/lib/python3.7/dist-packages/yaml/reader.py in check_printable(self, data) 142 position = self.index+(len(self.buffer)-self.pointer)+match.start() 143 raise ReaderError(self.name, position, ord(character), --> 144 'unicode', "special characters are not allowed") 145 146 def update(self, length): ReaderError: unacceptable character #x1f680: special characters are not allowed in "yolov5s.yaml", position 9 ``` --- models/yolo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/yolo.py b/models/yolo.py index c196d46f9efa..305f0ca0cc88 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -90,7 +90,7 @@ def __init__(self, cfg='yolov5s.yaml', ch=3, nc=None, anchors=None): # model, i else: # is *.yaml import yaml # for torch hub self.yaml_file = Path(cfg).name - with open(cfg, errors='ignore') as f: + with open(cfg, encoding='ascii', errors='ignore') as f: self.yaml = yaml.safe_load(f) # model dict # Define model