labelme标注后的数据去除单点和双点的标签

单点和双点的错误标签转化不成多边形,导致不能转化成实例分割的训练集所以在训练前需要去除掉

点击查看代码
import cv2
import numpy as np
import json
import os
# 去除一两个点的小polygon
def remove_specific_labels(json_file):
    # 读取JSON文件
    with open(json_file, 'rb+') as f:
        data = json.load(f)
    if"shapes" in data:
        new_shapes=[]
        for shape in data['shapes']:
            points = np.array(shape['points'], np.int32)
            if(len(points)<3):
                print("单点polygon",points)
            else:
                new_shapes.append(shape)
        data["shapes"]=new_shapes
        # data_small["shapes"]=new_shapes_small
    with open(json_file,'w',encoding='utf-8')as f:
        json.dump(data,f,ensure_ascii=False,indent=4)


def traverse_jsons_folder(folder_path):
    image_files = []
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.endswith(".json"):
                print(file)
                remove_specific_labels(os.path.join(root,file))

if __name__ == '__main__':
    # remove_specific_labels(r'D:\pic\see\0906\src\add24.json')
    traverse_jsons_folder('/home/administrator/gzj/pic/primary_tiao/src_copy/')

posted @   阳光天气  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 百万级群聊的设计实践
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
点击右上角即可分享
微信分享提示