官方Objection detection出问题

训练神经网络时,需要将标注好的数据转换成tensorflow特定数据,tfrecord。但是在转换时,发生以下错误:ValueError:Unicode strings with encoding declaration are not supported.Please use bytes or XML fragments without declaration.

 

  File "create_pascal_tf_record.py", line 185, in <module>
    tf.app.run()
  File "/home/chenyu/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "create_pascal_tf_record.py", line 174, in main
    xml = etree.fromstring(xml_str)
  File "src/lxml/lxml.etree.pyx", line 3213, in lxml.etree.fromstring (src/lxml/lxml.etree.c:82934)
  File "src/lxml/parser.pxi", line 1814, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:124471)
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
 

 

 

错误显示不支持的解码格式,以为时标注的xml文件出错了,就把相应的图片和标注文件删除了,发现还是出错。很感谢这篇博客的作者:https://blog.csdn.net/Fkk921912333/article/details/78537726 ,作者博客“解析 XML 字符串”部分,介绍了相关的xml文件解析方法,最主要的一句:print(etree.tostring(root, pretty_print=True).decode('utf-8'))。对比自己的creat_te_record文件,修改了读取文件时格式,即加入‘utf-8’,改变读取xml文件的编码方式,即可顺利转换数据。因为用的是tensorflow官方给的转换文件,具体语句为将xml = etree.fromstring(xml_str)改为xml = etree.fromstring(xml_str.encode('utf-8'))。可以据此更改自己的文件语句
 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值