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
- Python報錯:UnicodeDecodeError: 'gbk' codec can't decode byte ...PythonUnicodeError
- pipenv install error UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in positionErrorUnicode
- Python讀取csv檔案出現解碼錯誤UnicodeDecodeError: ‘utf-8‘ codec can‘t decodPythonUnicodeError
- python在用pandas對csv檔案處理的時候報UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb6。。。的錯誤PythonUnicodeError
- Python3.7使用pip install xxxx報錯:UnicodeDecodeError: 'gbk' codec can't decode bytePythonUnicodeError
- PIP3安裝報錯nicodeDecodeError: 'ascii' codec can't decode byte 0xc3ErrorASCII
- pip install ... ERROR: UnicodeDecodeError: ‘gbk‘ codec can‘t decode/ python setup.py egg_info CheckErrorUnicodePython
- Python——UnicodeEncodeError: 'ascii' codec can't encode/decode charactersPythonUnicodeErrorASCII
- Python3解決UnicodeEncodeError: 'ascii' codec can't encode characters in position 0PythonUnicodeErrorASCII
- day1 UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 2490: illegal multi...UnicodeError
- Invalid byte 3 of 3-byte UTF-8 sequence 解決方案
- byte轉16進位制String時為什麼要乘上0xff
- 【python爬蟲】用selenium爬時報錯UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\u2022‘Python爬蟲UnicodeError
- python cx_Oracle: UnicodeEncodeError: 'ascii' codec can't encode charactersPythonOracleUnicodeErrorASCII
- wget下載安裝時出現錯誤doesn‘t match requested host name錯誤wget
- MYSQL報1022錯誤:Can't write;duplicate key in table '.....'MySql
- Sublime Text 2報 Decode error - output not utf-8 錯誤的解決辦法Error
- 讀取nc錯誤
- [mac pip錯誤]Can't connect to HTTPS URL because the SSL module is not availableMacHTTPAI
- C# 聯合halcon讀取攝像頭時 報Invalid handle type in operator grab_image_async 錯誤C#
- RAC安裝時出現PRKC-1024 : Invalid netmask: eth0
- Can't Connect to MySQL Server on IP Address (10061) 錯誤的解決方案MySqlServer
- 在讀取資料時拼接圖片域名
- 讀取本地圖片地圖
- Android執行出現android Installation failed due to invalid URI! 錯誤處理AndroidAI
- file_get_content s()獲取https出現這個錯誤Unable to find the wrapperHTTPAPP
- python str與byte轉換 encode decodePython
- eslint --fix 報錯 can't not find modulesEsLint
- 考OCP在做vue和oracle賬號關聯的時候容易出現的錯誤:third invalid attemptVueOracle
- js實現圖片上下滾動background-positionJS
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock錯誤MySqlServer
- std::sort 錯誤"Expression : invalid operator <"Express
- Python 錯誤 SyntaxError: invalid character in identifierPythonErrorIDE
- PostgreSQL/LightDB copy ERROR: invalid byte sequence for encoding "UTF8": 0x00SQLErrorEncoding
- 解決安裝ubuntu系統時出現錯誤:(10, “debian-installer/locale doesn‘t exist“)Ubuntu