labelme2voc.py无法读取window下生成的json文件
在windows系统下,利用labelme标注图像生成的json文件,图像的路径是反斜杠的,例如:“imagePath”: “…\imgs\28.9_3.jpg”;如果在linunx系统下,运行 python labelme2voc.py --input_dir jsons --output_dir data_dataset_voc --labels labels.txt时,会提示错误:
Failed opening image file: jsons_win/…\stage_first\54_561_f.jpg
Traceback (most recent call last):
File “/home/zhangdeshan/.local/lib/python3.7/site-packages/labelme/label_file.py”, line 117, in load
base64.b64encode(imageData).decode(“utf-8”),
File “/data/envs/conda/lib/python3.7/base64.py”, line 58, in b64encode
encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not ‘NoneType’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “labelme2voc.py”, line 106, in
main(args)
File “labelme2voc.py”, line 52, in main
label_file = labelme.LabelFile(filename=filename)
File “/home/zhangdeshan/.local/lib/python3.7/site-

在Windows环境下运行labelme2voc.py时遇到LabelFileError,原因是路径中的''字符导致的问题。解决方法是在脚本中添加代码,将所有''替换为'/',以便在Linux系统中正确解析图片路径。
最低0.47元/天 解锁文章
1116





