-
大小: 3KB文件类型: .py金币: 1下载: 0 次发布日期: 2021-06-01
- 语言: Python
- 标签:
资源简介
Labelme标注工具 json批量生成,解决了两个问题:
1、生成的label.png不是灰度图8bits,
2、生成的label.png中,标注物体label不具备统一性
具体请看:https://blog.csdn.net/xjtdw/article/details/94741984
代码片段和文件信息
import argparse
import json
import os
import os.path as osp
import warnings
import copy
import numpy as np
import PIL.Image
from skimage import io
import yaml
from labelme import utils
NAME_LABEL_MAP = {
‘_background_‘: 0
“cat“: 1
“dog“: 2
# “basketball_court“: 3
# “ground_track_field“: 4
}
# LABEL_NAME_MAP = {
# 0: ‘_background_‘
# 1: “cat“
# 2: “dog“
#
# }
LABEL_NAME_MAP = [‘0: _background_‘
‘1: cat‘
‘2: dog‘]
def main():
parser = argparse.ArgumentParser()
parser.add_argument(‘json_file‘)
parser.add_argument(‘-o‘ ‘--out‘ default=None)
args = parser.parse_args()
json_file = args.json_file
list = os.listdir(json_file)
for i in range(0 len(list)):
path = os.path.join(json_file list[i])
filename = list[i][:-5] # .json
if os.path.isfile(path):
data = json.load(open(path))
img = utils.image.img_b64_to_arr(data[‘imageData‘])
lbl lbl_names = utils.shape.labelme_shapes_to_label(img.shape data[‘shapes‘]) # labelme_shapes_to_label
# modify labels according to NAME_LABEL_MAP
lbl_tmp = copy.copy(lbl)
for key_name in lbl_names:
old_lbl_val = lbl_names[key_name]
new_lbl_val = NAME_LABEL_MAP[key_name]
lbl_tmp[lbl == old_lbl_val] = new_lbl_val
lbl_names_tmp = {}
for key_na
评论
共有 条评论