在run maskrcnn代码时,训练自己数据需要批量转换json文件,下面是详细步骤:

cd 到/usr/local/lib/python3.6/dist-packages/labelme/cli路径,也就是labelme安装路径,修改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()
然后,cd 到想要放置生成文件的 文件夹 比如:labelme_json
run labelme_json_to_dataset +json文件夹路径

labelme 批量转换json文件 详细步骤相关推荐

  1. 超详细labelme批量处理json文件,json_to_dataset方法

    labelme批量处理json文件,json_to_dataset方法 第一步:找到json_to_dataset.py文件 第二步修改json_to_dataset.py文件 第三步找到labelm ...

  2. labelme批量转换json

    安装:https://mp.csdn.net/postedit/80924918 使用:https://github.com/wkentaro/labelme 单张转换: labelme_json_t ...

  3. labeme批量转换json文件_Python实现markdown文件批量转换为word

    Python实现markdown文件批量转换为word 正所谓,不会markdown的技术员不是老司机,自从用上markdown之后,人生又到了一波小高峰.有好东西怎么能不共享之,因此随之我不断的普( ...

  4. labelme标记数据后,批量处理json文件,生成标签

    1.安装labelme的过程省略,可参考别人 2.打开anaconda prompt 3.激活安装有labelme的虚拟环境 4.运用labelme命令打开labelme开始标记数据 5.处理json ...

  5. 将labelme生成的json文件转换成png图

    将labelme生成的json文件转换成png图 我图片的每个标记只有一类,所以转换成png图后,png只有0和1像素,因为单通道图的范围是0~255,0和1的区别很小,下面的程序可以对你标记的mas ...

  6. 批量转换json到java bean工具说明

    说明: Json已经在现代程序中使用的越来越多,把json字符串转换为java bean也越来越常见. 我之前写了一个小程序,使用java开发,批量把json转换为java bean,直接拷贝到项目中 ...

  7. Python常用小技巧(五)——批量读取json文件

    Python常用小技巧(五)--批量读取json文件 前言:其实Python能够批量读取很多文件,这里,本人以json文件为例(json是标注图片时生成的文件,记录有标注的坐标和标签,友情推荐标注图片 ...

  8. 批量将json文件转为jpg格式

    批量将json文件转为jpg格式 1.简介 labelme软件自带有将json文件转为jpg的代码,不过只限单张. 位于./cli/json_to_dataset.py. 2.批量生成代码 impor ...

  9. 【使用ChatGPT自动化】批量转换.csv文件为.xlsx文件

    第1次提问: 我:我想使用Python批量转换.csv文件为.xlsx文件,请你提供代码 它:好的,以下是使用Python批量转换.csv文件为.xlsx文件的代码: import os import ...

最新文章

  1. BZOJ 1050: [HAOI2006]旅行comf(枚举+并查集)
  2. 关于STM中SPI运用的NSS引脚解读
  3. C++golden section search黄金分割搜索的实现算法(附完整源码)
  4. E百科 | 基于MEC的边缘AI服务
  5. 17行代码AC——习题5-3 卡片游戏(Throwing cards away I, UVa 10935,约瑟夫环)_解题报告
  6. centos 启动一个redis_基于prometheus+grafana体系监控redis缓存服务
  7. Python 异步 IO 、协程、asyncio、async/await、aiohttp
  8. BugkuCTF-Reverse题easy-100(LCTF)
  9. 华为交换机屏蔽远程计算机,华为交换机远程telnet配置的小问题
  10. android获取文件夹里最新的文件夹,Android 获取已存在的文件所在目录下的所有文件为null。...
  11. c语言程序可以单独编译,c语言的函数能单独进行编译吗?
  12. java iecapt.exe_java替换url的域名和端口方法
  13. 电视家鸿蒙系统,ZNDS智能电视强烈推荐:机顶盒上好用的四款软件!
  14. OpManager引领智能运维未来的发展方向
  15. Message from debugger: Terminated due to signal 6
  16. linux匿名邮件,Linux下用mutt给QQ邮箱发匿名邮件
  17. 华为路由器接口如何区分_华为路由器接口管理命令有哪些
  18. Office 16 Click-to-Run Extensibility Component 卸载
  19. linux查看系统资源使用情况,Linux查看系统资源占用
  20. vant上传图片时压缩图片

热门文章

  1. XXXXXXX\android-sdk\\tools\zipalign.exe”无效
  2. Android-自定义UI模板
  3. 后台拼接字符串加双引号
  4. 快速排序的那些事儿(Kotlin)
  5. camunda工作流开发实战------04 请假流程实例
  6. 手机无线网卡最高支持到866Mbps
  7. 01改变世界:机械之美——机械时期的计算设备
  8. 小学计算机神奇的因特网教案,小学信息技术第三册全册教案(第一单元 神奇的动画城)...
  9. 2.4gwifi最高下载速度_宽带200m,光猫和无线一体的猫,5g和2.4g无线下速度多少是正常?...
  10. 超声波测距 c语言程序流程图,超声波测距程序(详细C语言数码管显示)