labelme:使用labelme_json_to_dataset转成dataset时,label_viz.png中的图例显示与标注不符
大家在使用labelme中的labelme_json_to_dataset的时候是否会出现此类问题:
即:右下角的图例显示不正确,虽然不会对训练造成影响,但是看着很别扭,因此对代码进行修改。
1)打开labelme安装包中的utils.py(位置:your_python_path\Lib\site-packages\label\utils.py),这里需要说明一下,如果你的python包中默认有utils.py的话,在使用labelme时会出错,最好将默认的py包改了个名字,如:util.py。
2)打开utils.py后,找到 def draw_label(label, img=None, label_names=None, colormap=None):
将:
for label_value, label_name in enumerate(label_names): if label_value not in label: continue if label_name.startswith('_'): continue fc = colormap[label_value] p = plt.Rectangle((0, 0), 1, 1, fc=fc) plt_handlers.append(p) plt_titles.append(label_name)
改为:
for label_value, label_name in enumerate(label_names): # if label_value not in label: # continue # if label_name.startswith('_'): # continue fc = colormap[label_value] p = plt.Rectangle((0, 0), 1, 1, fc=fc) plt_handlers.append(p) plt_titles.append(label_name)
对,就是把这两个if条件屏蔽。
3)我们再使用labelme_json_to_dataset时,就会显示正常了。
注:官方的labelme_json_to_dataset一次只能操作一个json文件,同时我们还需要把16位掩码文件(label.png)转成8位掩码文件,因此,小弟稍微改了下代码,所有文件一键生成,不再单去转码,直接生成数据集,直接训练即可,代码稍后奉上。