labelme安装与使用随记

比较:

  • labelimg完成的是对目标物的框选,最终完成的任务是目标检测。
  • labelme完成的是对目标物的分割,可以理解为更精细化的目标检测。

下面梳理一下安装labelme的过程:

step1: 打开anaconda prompt,创建虚拟环境

输入conda create -n labelme python=3.9

step2 :检查是否虚拟环境是否建立 conda env list

如图,已经安装好了

step3 :激活环境 conda activate labelme

使用labelme时需要安装多个库,依次进行

conda install pyqt

conda install pillow

pip install labelme

step4: 检查是否成功安装labelme

conda list

step5:和使用labelme类似,安装成功后先激活环境,再调用labelme即可。界面与labelimg类似。

区别是,labelme没有自动调整输出格式的功能,保存的是一个.json文件,后续需创建一个.json->.txt的python文件。这里借鉴了其他博主的方法(@csdn Jack_小明)

原文链接:blog.csdn.net/Wu_GuiMing/...

ini 复制代码
import json
import os

name_to_id = {'cat': 0, 'dog': 1} #此处需要根据你自己的数据集类型进行修改

def convert(img_size, box):
    dw = 1. / (img_size[0])
    dh = 1. / (img_size[1])
    x = (box[0] + box[2]) / 2.0
    y = (box[1] + box[3]) / 2.0
    w = abs(box[2] - box[0])
    h = abs(box[3] - box[1])
    x = x * dw
    w = w * dw
    y = y * dh
    h = h * dh
    return (x, y, w, h)


def decode_json(json_floder_path, txt_outer_path, json_name):
    txt_name = txt_outer_path + json_name[:-5] + '.txt'
    with open(txt_name, 'w') as f:
        json_path = os.path.join(json_floder_path, json_name)  # os路径融合
        data = json.load(open(json_path, 'r', encoding='gb2312', errors='ignore'))
        img_w = data['imageWidth']  # 图片的高
        img_h = data['imageHeight']  # 图片的宽
        isshape_type = data['shapes'][0]['shape_type']
        print(isshape_type)
        for i in data['shapes']:
            label_name = i['label']  # 得到json中你标记的类名
            if (i['shape_type'] == 'polygon'):  # 数据类型为多边形 需要转化为矩形
                x_max = 0
                y_max = 0
                x_min = 100000
                y_min = 100000
                for lk in range(len(i['points'])):
                    x1 = float(i['points'][lk][0])
                    y1 = float(i['points'][lk][1])
                    # print(x1)
                    if x_max < x1:
                        x_max = x1
                    if y_max < y1:
                        y_max = y1
                    if y_min > y1:
                        y_min = y1
                    if x_min > x1:
                        x_min = x1
                bb = (x_min, y_max, x_max, y_min)
            if (i['shape_type'] == 'rectangle'):  # 为矩形不需要转换
                x1 = float(i['points'][0][0])
                y1 = float(i['points'][0][1])
                x2 = float(i['points'][1][0])
                y2 = float(i['points'][1][1])
                bb = (x1, y1, x2, y2)
            bbox = convert((img_w, img_h), bb)
            try:
                f.write(str(name2id[label_name]) + " " + " ".join([str(a) for a in bbox]) + '\n')
            except:
                pass


if __name__ == "__main__":
    json_floder_path = '.\\json\\'  # 存放json的文件夹的绝对路径
    txt_outer_path = '.\\labels\\'  # 存放txt的文件夹绝对路径
    json_names = os.listdir(json_floder_path)
    print("共有:{}个文件待转化".format(len(json_names)))
    flagcount = 0
    for json_name in json_names:
        decode_json(json_floder_path, txt_outer_path, json_name)
        flagcount += 1
        print("还剩下{}个文件未转化".format(len(json_names) - flagcount))

    # break
    print('转化全部完毕')                        

又开始打标了-

完成打标后,转换文件格式,再调用YOLOv8-seg 实例分割onnx模型即可,下一篇文章再写了,苦命打标先 又要过去一天了- -

相关推荐
郝学胜-神的一滴4 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
秋天的怀念_David4 小时前
算法一千零一夜 · 第三十三夜 · 跳表
java·程序人生·算法
Pniubi7 小时前
力扣21合并两个有序链表
算法·leetcode·职场和发展
AIgorithmGEEK7 小时前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
上海潭龙东海科技有限公司9 小时前
智慧堆场动态模型三维实时孪生重构智能管控
大数据·网络·数据库·算法·重构
阿庆_AI研发工程师10 小时前
Stanford CS336 Lecture 10:大语言模型推理与性能优化
算法
用户73416810354811 小时前
基于MindSpore的深度残差收缩网络程序
算法
Pniubi11 小时前
力扣239.滑动窗口最大值(优先队列)
算法·leetcode·职场和发展
青少儿编程课堂13 小时前
第十八届蓝桥杯青少组图形化真题 + 全国青少年信息素养大赛 + 电子学会图形化考级:校园泡泡堂大挑战解析
c++·python·算法·bfs·信息学竞赛
超低空13 小时前
一文说清LRU算法
后端·算法·架构