tensorflow讀取圖片時出現錯誤UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid s
問題描述:tensorflow讀取圖片時出現錯誤UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid s
- 系統版本:windows7 64位旗艦版
- tensorflow版本:tensorf 1.4.0
- python版本:python 3.5.2
#coding:utf-8
import tensorflow as tf
import matplotlib.pyplot as plt
image = tf.gfile.FastGFile('image/1.jpg','r').read()
with tf.Session() as sess:
image = tf.image.decode_jpeg(image)
print(image.eval())
plt.imshow(image.eval())
plt.show()
出現錯誤:File "E:/python_work/lab/6.py", line 6, in <module>
image = tf.gfile.FastGFile('image/1.jpg','r').read()
問題分析:Python 3引入了用於開啟檔案的“r”和“rb”模式之間的區別。使用“r”模式將導致Python將檔案內容解釋為文字(在您的情況下(以及常見情況下)使用UTF-8編碼),但是錯誤訊息表明資料是二進位制格式(可能是某種基於變數名的影象格式)。改變程式碼使用模式“rb”應該可以解決這個問題,並在兩個版本的Python中工作:
image = tf.gfile.FastGFile('image/1.jpg','rb').read()
相關文章
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byteUnicodeError
- PyMySQL 獲取資料 'utf-8' codec can't decode byte 0xed in position 2: 錯誤MySql
- Python讀取檔案時出現UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position xx: 解決方案PythonUnicodeError
- pipenv install error UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in positionErrorUnicode
- Python報錯:UnicodeDecodeError: 'gbk' codec can't decode byte ...PythonUnicodeError
- pip install 報錯UnicodeDecodeError: 'ascii' codec can't decode byteUnicodeErrorASCII
- Python讀取csv檔案出現解碼錯誤UnicodeDecodeError: ‘utf-8‘ codec can‘t decodPythonUnicodeError
- python在用pandas對csv檔案處理的時候報UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb6。。。的錯誤PythonUnicodeError
- json.dumps錯誤:'utf8' codec can't decode byte解決方案JSON
- PIP3安裝報錯nicodeDecodeError: 'ascii' codec can't decode byte 0xc3ErrorASCII
- Python3.7使用pip install xxxx報錯:UnicodeDecodeError: 'gbk' codec can't decode bytePythonUnicodeError
- pip install ... ERROR: UnicodeDecodeError: ‘gbk‘ codec can‘t decode/ python setup.py egg_info CheckErrorUnicodePython
- Python3解決UnicodeEncodeError: 'ascii' codec can't encode characters in position 0PythonUnicodeErrorASCII
- Python——UnicodeEncodeError: 'ascii' codec can't encode/decode charactersPythonUnicodeErrorASCII
- day1 UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 2490: illegal multi...UnicodeError
- sublime 出現 [Decode error - output not utf-8]Error
- 異常: 'ascii' codec can't encode charactersASCII
- Invalid byte 3 of 3-byte UTF-8 sequence 解決方案
- byte轉16進位制String時為什麼要乘上0xff
- RMAN的"rman: can't open target"錯誤
- python報錯問題解決:'ascii' codec can't encode characterPythonASCII
- sublime text編譯時提示錯誤[Decode error - output not utf-8] compilation terminated編譯Error
- wget下載安裝時出現錯誤doesn‘t match requested host name錯誤wget
- react native 路徑對,但讀取圖片錯誤問題React Native
- can't assign requested address 錯誤解決
- 安裝Tomcat 5 出現Invalid index!錯誤求救TomcatIndex
- 在讀取資料時拼接圖片域名
- 讀取本地圖片地圖
- Sublime Text 2報 Decode error - output not utf-8 錯誤的解決辦法Error
- Sublime Text 2報“Decode error - output not utf-8”錯誤的解決辦法Error
- Windows 10更新時出現0x80070422錯誤Windows
- Sublime報Decode error - output not utf-8 or cp936 錯誤的解決辦法Error
- MYSQL報1022錯誤:Can't write;duplicate key in table '.....'MySql
- MySQL錯誤1042-Can't get hostname for your addressMySql
- 關於收到localhost modprobe: modprobe: Can't locate module ethX的錯誤localhost
- python cx_Oracle: UnicodeEncodeError: 'ascii' codec can't encode charactersPythonOracleUnicodeErrorASCII
- 移動檔案出現 invalid cross-device link 錯誤ROSdev
- JDBC 連oracle 時出現錯誤,,求助???JDBCOracle