一个高效且友好的TensorFlow图神经网络(GNN)框架:tf_geometric

tf_geometric 是一个高效且友好的图神经网络库,同时支持TensorFlow 1.x 和 2.x。

受到 usty1s/pytorch_geometric 项目的启发,我们为TensorFlow构建了一个图神经网络(GNN)库。
tf_geometric 同时提供面向对象接口(OOP API)和函数式接口(Functional API),你可以用它们来构建有趣的模型。

tf_geometric使用消息传递机制来实现图神经网络:相比于基于稠密矩阵的实现,它具有更高的效率;相比于基于稀疏矩阵的实现,它具有更友好的API。
除此之外,tf_geometric还为复杂的图神经网络操作提供了简易优雅的API。
下面的示例展现了使用tf_geometric构建一个图结构的数据,并使用多头图注意力网络(Multi-head GAT)对图数据进行处理的流程:


   import numpy as np
   import tf_geometric as tfg
   import tensorflow as tf

   graph = tfg.Graph(
       x=np.random.randn(5, 20),
       edge_index=[[0, 0, 1, 3],
                   [1, 2, 2, 1]]
   )

   print("Graph Desc: \n", graph)

   graph.convert_edge_to_directed()
   print("Processed Graph Desc: \n", graph)
   print("Processed Edge Index:\n", graph.edge_index)

   gat_layer = tfg.layers.GAT(units=4, num_heads=4, activation=tf.nn.relu)
   output = gat_layer([graph.x, graph.edge_index])
   print("Output of GAT: \n", output)

输出:


   Graph Desc:
    Graph Shape: x => (5, 20)  edge_index => (2, 4)    y => None

   Processed Graph Desc:
    Graph Shape: x => (5, 20)  edge_index => (2, 8)    y => None

   Processed Edge Index:
    [[0 0 1 1 1 2 2 3]
    [1 2 0 2 3 0 1 1]]

   Output of GAT:
    tf.Tensor(
   [[0.22443159 0.         0.58263206 0.32468423]
    [0.29810357 0.         0.19403605 0.35630274]
    [0.18071976 0.         0.58263206 0.32468423]
    [0.36123228 0.         0.88897204 0.450244  ]
    [0.         0.         0.8013462  0.        ]], shape=(5, 4), dtype=float32)

教程列表

使用示例进行快速入门

强烈建议您通过下面的示例代码来快速入门tf_geometric:

API列表

申明: 本文中部分文字、案例源于官网,将在后期的更新中不断丰富文中内容以及本文链接所指向的相关文章,如果侵犯了您的权益,可以联系我微.信(mtyjkh_)。

Original: https://blog.csdn.net/qq_38251616/article/details/122003893
Author: K同学啊
Title: 一个高效且友好的TensorFlow图神经网络(GNN)框架:tf_geometric

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/521176/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球