labelme等标注工具/数据增强工具输出JSON文件格式检查脚本

标注的文件太多了,还有用数据增强工具生成了一票的新数据。在转换或使用训练时候会报错,错误原因是json中语法有问题,这样会中断程序运行,调试造成很大困扰。

检查确实最后有问题,多写了一次

写一个脚本,用于检查文件夹下所有的json文件是否合规,不合规的记录并输出,然后自己改。

python 复制代码
import json
import glob
import os

# 获取文件夹中所有的JSON文件
json_files = glob.glob('*.json')

# 创建一个列表来存储存在语法错误的文件名
invalid_files = []

# 遍历所有的JSON文件
for json_file in json_files:
    try:
        with open(json_file, 'r') as f:
            print(json_file)
            # 尝试解析JSON文件
            data = json.load(f)
    except json.JSONDecodeError:
        # 如果解析失败,则添加文件名到invalid_files列表
        invalid_files.append(json_file)

# 输出有语法错误的JSON文件名
if invalid_files:
    print("以下文件存在语法错误:")
    for file in invalid_files:
        print(os.path.basename(file))
else:
    print("所有文件都无语法错误。")
相关推荐
花酒锄作田4 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪7 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽8 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战8 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋14 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python
曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama