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)

猜你喜欢

转载自blog.csdn.net/qq_26535271/article/details/82801220