diff --git a/mmcv/utils/config.py b/mmcv/utils/config.py index ab4eb02aa6..f48778de97 100644 --- a/mmcv/utils/config.py +++ b/mmcv/utils/config.py @@ -90,7 +90,8 @@ class Config: @staticmethod def _validate_py_syntax(filename): - with open(filename, 'r') as f: + with open(filename, 'r', encoding='utf-8') as f: + # Setting encoding explicitly to resolve coding issue on windows content = f.read() try: ast.parse(content) @@ -109,7 +110,8 @@ def _substitute_predefined_vars(filename, temp_config_name): fileBasename=file_basename, fileBasenameNoExtension=file_basename_no_extension, fileExtname=file_extname) - with open(filename, 'r') as f: + with open(filename, 'r', encoding='utf-8') as f: + # Setting encoding explicitly to resolve coding issue on windows config_file = f.read() for key, value in support_templates.items(): regexp = r'\{\{\s*' + str(key) + r'\s*\}\}' @@ -159,7 +161,8 @@ def _file2dict(filename, use_predefined_variables=True): temp_config_file.close() cfg_text = filename + '\n' - with open(filename, 'r') as f: + with open(filename, 'r', encoding='utf-8') as f: + # Setting encoding explicitly to resolve coding issue on windows cfg_text += f.read() if BASE_KEY in cfg_dict: