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-packages/labelme/label_file.py”, line 44, in init
self.load(filename)
File “/home/zhangdeshan/.local/lib/python3.7/site-packages/labelme/label_file.py”, line 135, in load
raise LabelFileError(e)
labelme.label_file.LabelFileError: a bytes-like object is required, not ‘NoneType’
在labelme2voc.py文件中,添加一段代码,主要作用是将’\‘替换为’//‘,以便linux能正确的识别图片路径
如下:
for filename in glob.glob(osp.join(args.input_dir, “*.json”)):
print(“Generating dataset from:”, filename)
with open(filename, “r”) as f: # 以只读方式打开文件
data = f.read() # 读取文件,读取为一个字符串
str_replace = data.replace(‘\’,‘/’)#将字符串中的某个字符进行替换
with open(filename, “w”) as f:#重新打开文件,选择写入模式
f.write(str_replace) # 将修改后的字符串重新写入文件
label_file = labelme.LabelFile(filename=filename)
print(label_file)
base = osp.splitext(osp.basename(filename))[0]
print(base)
out_img_file = osp.join(args.output_dir, “JPEGImages”, base + “.jpg”)
out_lbl_file = osp.join(
args.output_dir, “SegmentationClassnpy”, base + “.npy”
)
out_png_file = osp.join(
args.output_dir, “SegmentationClass”, base + “.png”
)