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("所有文件都无语法错误。")
相关推荐
aqi004 小时前
15天学会AI应用开发(八)使用向量数据库实现RAG功能
人工智能·python·大模型·ai编程·ai应用
Csvn5 小时前
`functools.lru_cache` —— 一行代码搞定缓存加速
后端·python
金銀銅鐵21 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup111 天前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi001 天前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 天前
Agent 流程编排
后端·python·agent
copyer_xyf1 天前
Agent RAG
后端·python·agent