error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

最近在研究tensorflow的工程,遇到一些小白鼠错误,记录一下。

问题:error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

解决:

def _process_image(filename, coder):
  with tf.gfile.FastGFile(filename, 'r') as f:
    image_data = f.read()

  # image_data = image_data.rstrip("\n").decode("utf-16")
  # image_data = image_data.split("\r\n")
  image = coder.decode_png(image_data)

修改为:

def _process_image(filename, coder):
  with tf.gfile.FastGFile(filename, 'rb') as f:
    image_data = f.read()

  # image_data = image_data.rstrip("\n").decode("utf-16")
  # image_data = image_data.split("\r\n")
  image = coder.decode_png(image_data)

你可能感兴趣的:(TF)