|
import os |
|
import glob |
|
import json |
|
from typing import Dict, List |
|
from tqdm import tqdm |
|
|
|
""" |
|
Generate Metadata for this dataset |
|
{ |
|
"data": [ |
|
{ |
|
"depth": "depths/COME_Train_1.png", |
|
"rgb": "RGB/COME_Train_1.jpg", |
|
"gt": "GT/COME_Train_1.png" |
|
}, |
|
... |
|
] |
|
} |
|
""" |
|
|
|
depths = glob.glob("depths/*") |
|
gts = glob.glob("GT/*") |
|
rgbs = glob.glob("RGB/*") |
|
|
|
metadata: List[Dict[str, str]] = [] |
|
|
|
for depth in tqdm(depths): |
|
name = os.path.basename(depth).split(".")[0] |
|
|
|
gts = glob.glob(f"GT/{name}.*") |
|
if len(gts) != 1: |
|
raise Exception(f"Inconsitent corresponding GT of name {name}, gts = ", gts) |
|
gt = gts[0] |
|
|
|
rgbs = glob.glob(f"RGB/{name}.*") |
|
if len(rgbs) != 1: |
|
raise Exception(f"Inconsitent corresponding RGB of name {name}, rgbs = ", rgbs) |
|
rgb = rgbs[0] |
|
|
|
metadata.append( |
|
{ |
|
"depth": depth, |
|
"gt": gt, |
|
"rgb": rgb, |
|
"name": name, |
|
} |
|
) |
|
|
|
|
|
json_object = json.dumps(dict(metadata=metadata), indent=4) |
|
|
|
|
|
with open("metadata.json", "w") as outfile: |
|
outfile.write(json_object) |
|
|
|
os.system('zip -r -qq train.zip depths GT RGB metadata.json generate_metadata.py') |
|
|
|
|