ornithoscope / mergesets.py
gdamms's picture
fix: iNatv2 directory
4f005f7
raw
history blame
781 Bytes
import os
import json
dir = 'annotations'
merged = {}
excluded = [
'task_2021-03-01_09',
'task_2021-03-01_10',
'task_20210526_UPS',
'task_20210611_Lab',
'task_20210612_1_Lab',
'task_20210705-07_balacet',
'task_20211204_Orlu',
'task_21-01-2021',
]
def iter_files(path, callback):
if os.path.isfile(path):
callback(path)
elif os.path.isdir(path):
for entry in os.scandir(path):
iter_files(entry.path, callback)
def merge_files(path):
global merged
for name in excluded:
if name in path:
return
with open(path, 'r') as f:
data = json.load(f)
merged = merged | data
iter_files(dir, merge_files)
with open('sets/DS7_train.json', 'w') as f:
json.dump(merged, f)