Skip to content

Commit

Permalink
Remove encoding='ascii' (ultralytics#4413)
Browse files Browse the repository at this point in the history
* Remove `encoding='ascii'`

* Reinstate `encoding='ascii'` in emojis()
  • Loading branch information
glenn-jocher authored and CesarBazanAV committed Sep 29, 2021
1 parent 9bd5b60 commit 3bb8d4f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion utils/autoanchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def print_results(k):
return k

if isinstance(dataset, str): # *.yaml file
with open(dataset, encoding='ascii', errors='ignore') as f:
with open(dataset, errors='ignore') as f:
data_dict = yaml.safe_load(f) # model dict
from utils.datasets import LoadImagesAndLabels
dataset = LoadImagesAndLabels(data_dict['train'], augment=True, rect=True)
Expand Down
2 changes: 1 addition & 1 deletion utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def hub_ops(f, max_dim=1920):
im.save(im_dir / Path(f).name, quality=75) # save

zipped, data_dir, yaml_path = unzip(Path(path))
with open(check_file(yaml_path), encoding='ascii', errors='ignore') as f:
with open(check_file(yaml_path), errors='ignore') as f:
data = yaml.safe_load(f) # data dict
if zipped:
data['path'] = data_dir # TODO: should this be dir.resolve()?
Expand Down
4 changes: 2 additions & 2 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def is_pip():

def emojis(str=''):
# Return platform-dependent emoji-safe version of string
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
return str.encode().decode(encoding='ascii', errors='ignore') if platform.system() == 'Windows' else str


def file_size(file):
Expand Down Expand Up @@ -250,7 +250,7 @@ def check_dataset(data, autodownload=True):

# Read yaml (optional)
if isinstance(data, (str, Path)):
with open(data, encoding='ascii', errors='ignore') as f:
with open(data, errors='ignore') as f:
data = yaml.safe_load(f) # dictionary

# Parse yaml
Expand Down
6 changes: 3 additions & 3 deletions utils/loggers/wandb/wandb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def check_wandb_resume(opt):


def process_wandb_config_ddp_mode(opt):
with open(check_file(opt.data), encoding='ascii', errors='ignore') as f:
with open(check_file(opt.data), errors='ignore') as f:
data_dict = yaml.safe_load(f) # data dict
train_dir, val_dir = None, None
if isinstance(data_dict['train'], str) and data_dict['train'].startswith(WANDB_ARTIFACT_PREFIX):
Expand Down Expand Up @@ -152,7 +152,7 @@ def __init__(self, opt, run_id, job_type='Training'):
self.wandb_artifact_data_dict = self.check_and_upload_dataset(opt)

elif opt.data.endswith('_wandb.yaml'): # When dataset is W&B artifact
with open(opt.data, encoding='ascii', errors='ignore') as f:
with open(opt.data, errors='ignore') as f:
data_dict = yaml.safe_load(f)
self.data_dict = data_dict
else: # Local .yaml dataset file or .zip file
Expand Down Expand Up @@ -186,7 +186,7 @@ def check_and_upload_dataset(self, opt):
opt.single_cls,
'YOLOv5' if opt.project == 'runs/train' else Path(opt.project).stem)
print("Created dataset config file ", config_path)
with open(config_path, encoding='ascii', errors='ignore') as f:
with open(config_path, errors='ignore') as f:
wandb_data_dict = yaml.safe_load(f)
return wandb_data_dict

Expand Down

0 comments on commit 3bb8d4f

Please sign in to comment.