TypeError: ‘b\... has type str, but expected one of: bytes

报错信息:

Traceback (most recent call last):
  File "D:\ProgramSoftware\Anaconda3\envs\tensorflow1.0\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "D:\ProgramSoftware\Anaconda3\envs\tensorflow1.0\lib\threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "build_tfrecord.py", line 210, in _process_image_files
    sequence_example = _to_sequence_example(image, decoder, vocab)
  File "build_tfrecord.py", line 157, in _to_sequence_example
    "image/data": _bytes_feature(encoded_image),
  File "build_tfrecord.py", line 125, in _bytes_feature
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[str(value)]))
TypeError: 'b\'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00\\x01\\x00\\x01\\x00\\x00\\xff\\xdb\\ has type str, but expected one of: bytes

解决方法:

将以下代码:

def _bytes_feature(value):
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[str(value)]))

修改为: 

def _bytes_feature(value):
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value.encode('utf-8') if type(value)==str else value]))

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值