TypeError: 'RGB' has type str, but expected one of: bytes

在使用Python3+(本人Python3.5)运行21个项目玩转深度学习第三个项目的时候。在执行数据转换操作

python data_convert.py -t pic/ \
  --train-shards 2 \
  --validation-shards 2 \
  --num-threads 2 \
  --dataset-name satellite

出现了 ‘’TypeError: 'RGB' has type str, but expected one of: bytes‘’,原因是Python2+与Python3+使用格式不对。经以下修改成功执行数据转换。

colorspace = 'RGB'.encode()
channels = 3
image_format = 'JPEG'.encode()

example = tf.train.Example(features=tf.train.Features(feature={
    'image/height': _int64_feature(height),
    'image/width': _int64_feature(width),
    'image/colorspace': _bytes_feature(colorspace),
    'image/channels': _int64_feature(channels),
    'image/class/label': _int64_feature(label),
    'image/class/text': _bytes_feature(text.encode()),
    'image/format': _bytes_feature(image_format),
    'image/filename': _bytes_feature(os.path.basename(filename.encode())),
    'image/encoded': _bytes_feature(image_buffer)}))
return example

INFO:root:2018-11-27 17:45:23.217677 [thread 0]: Processed 1000 of 2400 images in thread batch.
INFO:root:2018-11-27 17:45:23.219677 [thread 1]: Processed 1000 of 2400 images in thread batch.
INFO:root:2018-11-27 17:45:24.021429 [thread 0]: Processed 2000 of 2400 images in thread batch.
INFO:root:2018-11-27 17:45:24.025384 [thread 1]: Processed 2000 of 2400 images in thread batch.
INFO:root:2018-11-27 17:45:24.336195 [thread 0]: Wrote 2400 images to pic/satellite_train_00000-of-00002.tfrecord
INFO:root:2018-11-27 17:45:24.336302 [thread 0]: Wrote 2400 images to 2400 shards.
INFO:root:2018-11-27 17:45:24.348348 [thread 1]: Wrote 2400 images to pic/satellite_train_00001-of-00002.tfrecord
INFO:root:2018-11-27 17:45:24.348439 [thread 1]: Wrote 2400 images to 2400 shards.
INFO:root:2018-11-27 17:45:24.407238: Finished writing all 4800 images in data set.

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值