发布于2020-06-06 22:02 阅读(3722) 评论(0) 点赞(18) 收藏(4)
design by ht
基于视频教程:https://www.bilibili.com/video/BV16b411G7kB?p=1修改
教学视频:https://www.bilibili.com/video/av21676110?from=search&seid=9067865995586509468
Blog教学:https://blog.csdn.net/a838771230/article/details/80968049
Attention:下载最新版本、安装时添加环境变量
Blog教学:https://blog.csdn.net/DuanTuiXiaoALi/article/details/78295053
1.打开 Anaconda promt
2.查看python版本 输入 python -V
3.输入 conda create–name=labelme python=3.X(根据下载的python版本而定)
4.输入 conda activate labelme
5.输入 pip install pyqt5
6.输入 conda install pillow
7.输入 pip install labelme==3.16.2
Blog教学:https://blog.csdn.net/yql_617540298/article/details/81110685
1.在lableme安装目录下有C:\Users\ht\anaconda3\envs\labelme\Lib\site-packages\labelme\cli目录,可以看到json_to_dataset.py文件
2.修改json_to_dataset.py
import argparse
import json
import os
import os.path as osp
import warnings
import PIL.Image
import yaml
from labelme import utils
import base64
def main():
warnings.warn("This script is aimed to demonstrate how to convert the\n"
"JSON file to a single image dataset, and not to handle\n"
"multiple JSON files to generate a real-use dataset.")
parser = argparse.ArgumentParser()
parser.add_argument('json_file')
parser.add_argument('-o', '--out', default=None)
args = parser.parse_args()
json_file = args.json_file
if args.out is None:
out_dir = osp.basename(json_file).replace('.', '_')
out_dir = osp.join(osp.dirname(json_file), out_dir)
else:
out_dir = args.out
if not osp.exists(out_dir):
os.mkdir(out_dir)
count = os.listdir(json_file)
for i in range(0, len(count)):
path = os.path.join(json_file, count[i])
if os.path.isfile(path):
data = json.load(open(path))
if data['imageData']:
imageData = data['imageData']
else:
imagePath = os.path.join(os.path.dirname(path), data['imagePath'])
with open(imagePath, 'rb') as f:
imageData = f.read()
imageData = base64.b64encode(imageData).decode('utf-8')
img = utils.img_b64_to_arr(imageData)
label_name_to_value = {'_background_': 0}
for shape in data['shapes']:
label_name = shape['label']
if label_name in label_name_to_value:
label_value = label_name_to_value[label_name]
else:
label_value = len(label_name_to_value)
label_name_to_value[label_name] = label_value
# label_values must be dense
label_values, label_names = [], []
for ln, lv in sorted(label_name_to_value.items(), key=lambda x: x[1]):
label_values.append(lv)
label_names.append(ln)
assert label_values == list(range(len(label_values)))
lbl = utils.shapes_to_label(img.shape, data['shapes'], label_name_to_value)
captions = ['{}: {}'.format(lv, ln)
for ln, lv in label_name_to_value.items()]
lbl_viz = utils.draw_label(lbl, img, captions)
out_dir = osp.basename(count[i]).replace('.', '_')
out_dir = osp.join(osp.dirname(count[i]), out_dir)
if not osp.exists(out_dir):
os.mkdir(out_dir)
PIL.Image.fromarray(img).save(osp.join(out_dir, 'img.png'))
#PIL.Image.fromarray(lbl).save(osp.join(out_dir, 'label.png'))
utils.lblsave(osp.join(out_dir, 'label.png'), lbl)
PIL.Image.fromarray(lbl_viz).save(osp.join(out_dir, 'label_viz.png'))
with open(osp.join(out_dir, 'label_names.txt'), 'w') as f:
for lbl_name in label_names:
f.write(lbl_name + '\n')
warnings.warn('info.yaml is being replaced by label_names.txt')
info = dict(label_names=label_names)
with open(osp.join(out_dir, 'info.yaml'), 'w') as f:
yaml.safe_dump(info, f, default_flow_style=False)
print('Saved to: %s' % out_dir)
if __name__ == '__main__':
main()
1.打开 Anaconda promt
2.输入 activate labelme
3.输入 labelme
4.开始标记
5.在 lableme安装目录下有C:\Users\ht\anaconda3\envs\labelme\Scripts目录,可以看到labelme_json_to_dataset.exe文件
6.输入 cd C:\Users\ht\anaconda3\envs\labelme\Scripts
7.标注好的所有json文件全放到文件夹F:\Labelme\json
8.输入 labelme_json_to_dataset.exe F:\Labelme\json
9.生成的文件在 C:\Users\ht\anaconda3\envs\labelme\Scripts
作者:怪兽爸爸
链接:https://www.pythonheidong.com/blog/article/410406/49cf4013fa4001d76aaf/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!