CoolFace
Apppublic

kalpkanungo/SceneGraphNet

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
scene_graph.py25 linesDownload Raw Back to src
1import networkx as nx2 3 4def build_graph(relations):5    G = nx.DiGraph()6 7    seen = set()8 9    for rel in relations:10        subj = rel["subject"]11        obj = rel["object"]12        predicate = rel["relation"]13 14        key = (subj, obj, predicate)15 16        17        if key in seen:18            continue19        seen.add(key)20 21        G.add_node(subj)22        G.add_node(obj)23        G.add_edge(subj, obj, label=predicate)24 25    return G