python-lmdb using log

1
with open(imagePath, 'r') as f:
     imageBin = f.read()

error:

  imageBin = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence

Solution:
When open byte file is opened, the parameter added to 'b'

with open(imagePath, 'rb') as f:
     imageBin = f.read()
2 are required to write information encoded into binary form
imageKey = ('image-%09d' % cnt).encode()
labelKey = ('label-%09d' % cnt).encode()
cache[imageKey] = imageBin
cache[labelKey] = label.encode()

Guess you like

Origin www.cnblogs.com/yeran/p/11202041.html