去除labelme空的标注文件和对应的图片
去除labelme空的标注文件和对应的图片
点击查看代码
import os
import json
def is_empty_labelme_file(file_path):
with open(file_path, 'r') as f:
data = json.load(f)
# 检查图像数据是否存在
# if 'imageData' not in data:
# return True
# 检查标注列表是否为空
if len(data['shapes']) == 0:
return True
return False
def remove_empty_labelme_files(dir_path):
for filename in os.listdir(dir_path):
file_path = os.path.join(dir_path, filename)
if filename.endswith('.json') and is_empty_labelme_file(file_path):
file_name,old_suffix=os.path.splitext(filename)
jpg_filename=file_name+".jpg"
jpg_file_path=os.path.join(dir_path,jpg_filename)
json_file_path=file_path
print(f"Removed empty file: {jpg_file_path}")
print(f"Removed empty file: {json_file_path}")
print("")
os.remove(jpg_file_path)
os.remove(json_file_path)
# 使用示例
labelme_dir = '/home/administrator/gzj/pic/primary_ban/src_copy_coco/cutted_generated' # 替换为你的labelme文件夹路径
remove_empty_labelme_files(labelme_dir)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 百万级群聊的设计实践
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期