21个TensorFlow项目转换tfrecord:tf.train.Feature TypeError: 'RGB' has type str, but expected one of: bytes

最近在看21个TensorFlow项目一书中,由于我环境是Python3.5,项目中环境应该是Python2。运行第三章data_prepare文件夹下data_convert.py将图片转换为tfrecord格式时出现

TypeError: 'range' object does not support item assignment

此处错误是因为Python3 range返回的不是list,修改:tfrecord.py第340行将

shuffled_index = range(len(filenames))

修改为

shuffled_index = list(range(len(filenames)))

 

再次运行data_convert.py时出现下列错误:

UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illega

TypeError:tf.train.Feature TypeError: 'RGB' has type str, but expected one of: bytes

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

查找了相关资料错误原因可见https://blog.csdn.net/qq_29921623/article/details/80047339

需要修改下列地方:

tfrecord.py第160行改为  with open(filename, 'rb') as f:

tfrecord.py第94和96行修改为  colorspace = b'RGB'     image_format = b'JPEG'

tfrecord.py第104行修改为  'image/class/text': _bytes_feature(str.encode(text)),

tfrecord.py第106行修改为   'image/filename':_bytes_feature(os.path.basename(str.encode(filename))),

 

再次运行data_convert.py  (python data_convert.py -t pic/ --train-shards 2 --validation-shards 2 --num-threads 2 --dataset-name satellite)

评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值