运行Tensorflow2升级脚本触发编码错误
Running the Tensorflow2 upgrade Script triggers an encoding error
我目前正在尝试使用 https://www.tensorflow.org/guide/upgrade 中提供的 jupyter notebook 升级脚本以与 tensorflow2 兼容,这样我就可以 运行 它在 google colab 中,但是当我 运行 这个单元格(来自 windows 中的 Anaconda 环境)时:
!tf_upgrade_v2 \
--infile D:/Multiclass.py\
--outfile /tmp/upgraded_Multiclass_CNN_V01_31012020Copy.py
我收到一个编码错误:
Traceback (most recent call last):
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\ProgramData\Miniconda3\envs\Env_DLexp1\Scripts\tf_upgrade_v2.exe\__main__.py", line 7, in <module>
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\tf_upgrade_v2_main.py", line 139, in main
args.input_file, output_file, upgrade)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\tf_upgrade_v2_main.py", line 40, in process_file
upgrader.process_file(in_filename, out_filename)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\ast_edits.py", line 900, in process_file
temp_file)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\ast_edits.py", line 958, in process_opened_file
lines = in_file.readlines()
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 14: character maps to <undefined>
我通常会通过这样做将编码更改为 utf-8
:open(path, mode, encoding='UTF8')
,但在这种情况下我一无所知。我不是程序员,所以我的熟练程度很有限。请帮我理解这个错误。
尝试在 ast_edits.py 中编辑函数 process_file
的第 918 行中的 with open
并指定编码='utf-8',这样在函数 process_opened_file
中文件可以用utf-8读取。
我目前正在尝试使用 https://www.tensorflow.org/guide/upgrade 中提供的 jupyter notebook 升级脚本以与 tensorflow2 兼容,这样我就可以 运行 它在 google colab 中,但是当我 运行 这个单元格(来自 windows 中的 Anaconda 环境)时:
!tf_upgrade_v2 \
--infile D:/Multiclass.py\
--outfile /tmp/upgraded_Multiclass_CNN_V01_31012020Copy.py
我收到一个编码错误:
Traceback (most recent call last):
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\ProgramData\Miniconda3\envs\Env_DLexp1\Scripts\tf_upgrade_v2.exe\__main__.py", line 7, in <module>
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\tf_upgrade_v2_main.py", line 139, in main
args.input_file, output_file, upgrade)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\tf_upgrade_v2_main.py", line 40, in process_file
upgrader.process_file(in_filename, out_filename)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\ast_edits.py", line 900, in process_file
temp_file)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\tools\compatibility\ast_edits.py", line 958, in process_opened_file
lines = in_file.readlines()
File "d:\programdata\miniconda3\envs\env_dlexp1\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 14: character maps to <undefined>
我通常会通过这样做将编码更改为 utf-8
:open(path, mode, encoding='UTF8')
,但在这种情况下我一无所知。我不是程序员,所以我的熟练程度很有限。请帮我理解这个错误。
尝试在 ast_edits.py 中编辑函数 process_file
的第 918 行中的 with open
并指定编码='utf-8',这样在函数 process_opened_file
中文件可以用utf-8读取。