標注的文件太多了,還有用數(shù)據(jù)增強工具生成了一票的新數(shù)據(jù)。在轉(zhuǎn)換或使用訓(xùn)練時候會報錯,錯誤原因是json中語法有問題,這樣會中斷程序運行,調(diào)試造成很大困擾。
檢查確實最后有問題,多寫了一次文章來源:http://www.zghlxwxcb.cn/news/detail-756805.html
寫一個腳本,用于檢查文件夾下所有的json文件是否合規(guī),不合規(guī)的記錄并輸出,然后自己改。文章來源地址http://www.zghlxwxcb.cn/news/detail-756805.html
import json
import glob
import os
# 獲取文件夾中所有的JSON文件
json_files = glob.glob('*.json')
# 創(chuàng)建一個列表來存儲存在語法錯誤的文件名
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("所有文件都無語法錯誤。")
到了這里,關(guān)于labelme等標注工具/數(shù)據(jù)增強工具輸出JSON文件格式檢查腳本的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!