import json
import os
OldJsonPath="/media/cynere/Data/堅果云/我的堅果云/json"
newJsonPath="/media/cynere/Data/堅果云/我的堅果云/newjson"
if not os.path.exists(newJsonPath):
os.makedirs(newJsonPath)
Files=os.listdir(OldJsonPath)
for file in Files:
path=OldJsonPath+'/'+file
dic=json.load(open(path,encoding='utf-8'))
dic["imagePath"]=r'/media/cynere/Data/堅果云/我的堅果云/image1'
newpath=newJsonPath+'/'+file
with open(newpath,'w',encoding='utf-8') as f:
json.dump(dic,f)
通過json生成訓練數(shù)據(jù)
labelme_json_to_dataset filename.json
如果需要批量轉(zhuǎn)換:這個shell即可
#!/bin/bash
dir=`ls /media/cynere/Data/堅果云/我的堅果云/newjson/` #定義遍歷的目錄
path="/media/cynere/Data/堅果云/我的堅果云/newjson/" #名字與上一行相同
for i in $dir
do
labelme_json_to_dataset ${path}$i
#echo $i
done