FactualSceneGraph场景图生成
- 安装
- Demo
安装
pip install FactualSceneGraph
Demo
from factual_scene_graph.parser.scene_graph_parser import SceneGraphParserparser = SceneGraphParser('lizhuang144/flan-t5-base-VG-factual-sg', device='cpu')
text_graph = parser.parse(["2 beautiful pigs are flying on the sky with 2 bags on their backs"], beam_size=1, return_text=True)
graph_obj = parser.parse(["2 beautiful and strong pigs are flying on the sky with 2 bags on their backs"], beam_size=5, return_text=False,max_output_len=128)print(text_graph[0])
# Output: ( pigs , is , 2 ) , ( pigs , is , beautiful ) , ( bags , on back of , pigs ) , ( pigs , fly on , sky ) , ( bags , is , 2 )from sng_parser.utils import tprint
tprint(graph_obj[0])
场景图格式输出如下,视觉上更直观,原本输出是一个字典。
Entities:
+----------+------------+------------------+
| Entity | Quantity | Attributes |
|----------+------------+------------------|
| bags | 2 | |
| backs | | |
| pigs | 2 | strong,beautiful |
| sky | | |
+----------+------------+------------------+
Relations:
+-----------+------------+----------+
| Subject | Relation | Object |
|-----------+------------+----------|
| bags | on | backs |
| pigs | fly on | sky |
+-----------+------------+----------+