pip install graphviz easydev


node와 edge로 이루어진 그래프를 만들며,

간단한 코드로 시각화가 가능하다.


documents

https://graphviz.readthedocs.io/en/stable/



아래는 간단한 시각화 예시를 작성한 것이다.
sg = gv.Digraph() # 그래프 생성
anns_rel_n2c = annotation_util.get_rel_n2c()

for obj_idx, obj_info in enumerate(scene_info['visible_object']): # object node, 속성 node/edge 추가
    with sg.subgraph(name=str(obj_idx)) as obj_g:
        obj_g.node(str(obj_info['id']), label=obj_info['name'], shape='box')
        # is_open 추가
        obj_g.node(str(obj_info['id'])+'_isOpen', label={-1:'o_un', 0:'close', 1:'open'}[obj_info['is_open']], shape='ellipse', style='filled', color='lightgrey')
        obj_g.edge(str(obj_info['id'])+'_isOpen', str(obj_info['id']), dir='none')

        # color 추가
        obj_g.node(str(obj_info['id']) + '_color', label=obj_info['color'], shape='ellipse', style='filled', color='lightgrey')
        obj_g.edge(str(obj_info['id']) + '_color', str(obj_info['id']), dir='none')

for relaion in scene_info['relaion']: # 관계 edge 추가
    sg.edge(str(relaion['subject_id']), str(relaion['object_id']), label='  '+anns_rel_n2c[relaion['rel_class']])

sg.render('./gv_temp.gv', view=True, cleanup=True) # 랜더링


+ Recent posts