在使用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