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模型即可,下一篇文章再写了,苦命打标先 又要过去一天了- -

相关推荐
m0_692457103 分钟前
图像噪点消除
人工智能·算法
2401_841495645 分钟前
【Python高级编程】图着色动态可视化 APP
python·算法·matplotlib·tkinter·回溯法·图着色算法·动态可视化工具
youngee1128 分钟前
hot100-53搜索旋转排序数组
数据结构·算法·leetcode
烟雨梵兮30 分钟前
-刷题小结19
算法
爱学大树锯43 分钟前
1361 · 文字并排
算法
Tisfy1 小时前
LeetCode 2483.商店的最少代价:两次遍历 -> 一次遍历
算法·leetcode·题解·遍历
YGGP1 小时前
【Golang】LeetCode 279. 完全平方数
算法·leetcode
im_AMBER1 小时前
Leetcode 87 等价多米诺骨牌对的数量
数据结构·笔记·学习·算法·leetcode
import_random1 小时前
[算法]时间序列(介绍)
算法
wuk9981 小时前
MATLAB中求解和分析马蒂厄方程
人工智能·算法·matlab