python3环境下 tensorflow环境中经常遇到'*' has type str, but expected one of: bytes问题的解决

本文介绍了解决在使用TensorFlow时遇到的与Python3兼容性问题的方法。主要针对处理flowers数据集时出现的'jpg'类型错误,通过在'jpg'前加上'b'使其符合Python3的字节处理标准。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文:http://blog.youkuaiyun.com/sparkexpert/article/details/70230072

python3环境下 tensorflow环境中经常遇到'*' has type str, but expected one of: bytes问题的解决


为了对flowers数据集进行训练,于是调用了tensorflow的slim模块中的download_and_convert_flowers.py文件进行处理,


但是下载完成之后,执行过程中碰到一个问题:'jpg' has type str, but expected one of: bytes


看来tensorflow默认的源码都是基于python2环境下的。


而python3环境下是需要额外加个字符的。因此针对这种问题,只能修改源码:


具体修改如下:即在'jpg'前面加一个字母:b,即代表以字节的方式来进行处理。



            example = dataset_utils.image_to_tfexample(
                image_data, b'jpg', height, width, class_id)
            tfrecord_writer.write(example.SerializeToString())


修改完,再次执行这个文档,果然顺利通过:

>> Converting image 348/350 shard 4
>> Converting image 349/350 shard 4
>> Converting image 350/350 shard 4


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值