File size: 1,260 Bytes
6651025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55aff06
6651025
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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,
        }
    )

# Serializing json
json_object = json.dumps(dict(metadata=metadata), indent=4)

# Writing to sample.json
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')