1
with open(imagePath, 'r') as f:
imageBin = f.read()
错误:
imageBin = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence
解决方法:
open文件时按字节打开,参数加入 ‘b’
with open(imagePath, 'rb') as f:
imageBin = f.read()
2写入的信息都需要编码为二进制形式
imageKey = ('image-%09d' % cnt).encode()
labelKey = ('label-%09d' % cnt).encode()
cache[imageKey] = imageBin
cache[labelKey] = label.encode()