Spaces:
Running
Running
File size: 661 Bytes
c858478 | 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 | import json
LABELS_PATH = "data/relationship_dataset/labels.json"
OUTPUT_PATH = "data/relationship_dataset/labels_encoded.json"
MAP_PATH = "data/relationship_dataset/label_map.json"
with open(LABELS_PATH) as f:
labels = json.load(f)
predicates = sorted(list(set([item["predicate"] for item in labels])))
label_map = {p: i for i, p in enumerate(predicates)}
encoded = []
for item in labels:
encoded.append({
"image": item["image"],
"label": label_map[item["predicate"]]
})
with open(OUTPUT_PATH, "w") as f:
json.dump(encoded, f)
with open(MAP_PATH, "w") as f:
json.dump(label_map, f)
print("Classes:", len(label_map)) |