tilldream 发表于 2019-3-14 19:20:25

LeCun推荐:最新PyTorch图神经网络库,速度快15倍(GitHub+论文)

<p style="max-width: 100%; min-height: 1em; letter-spacing: 0.544px; color: rgb(62, 62, 62); font-size: 16px; text-align: center; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">过去十年来,深度学习方法(例如卷积神经网络和递归神经网络)在许多领域取得了前所未有的成就,例如计算机视觉和语音识别。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">研究者主要将深度学习方法应用于欧氏结构数据&nbsp;(Euclidean domains),但在许多重要的应用领域,如生物学、物理学、网络科学、推荐系统和计算机图形学,可能不得不处理非欧式结构的数据,比如图和流形。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">直到最近,深度学习在这些特定领域的采用一直很滞后,主要是因为数据的非欧氏结构性质使得基本操作(例如卷积)的定义相当困难。在这个意义上,<strong>几何深度学习</strong>将深度学习技术扩展到了图/流形结构数据。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">图神经网络&nbsp;(GNN)</span></strong><span style="letter-spacing: 0.5px;font-size: 15px;">是近年发展起来的一个很有前景的深度学习方向,也是一种强大的<strong>图、点云和流形表示学习方法</strong>。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">然而,实现&nbsp;GNN&nbsp;具有挑战性,因为需要在高度稀疏且不规则、不同大小的数据上实现高&nbsp;GPU&nbsp;吞吐量。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">近日,德国多特蒙德工业大学的研究者两位&nbsp;Matthias Fey&nbsp;和&nbsp;Jan E. Lenssen,提出了一个</span><span style="letter-spacing: 0.5px;font-size: 15px;color: rgb(255, 104, 39);"><strong>基于&nbsp;PyTorch&nbsp;的几何深度学习扩展库&nbsp;PyTorch Geometric (PyG)</strong></span><span style="letter-spacing: 0.5px;font-size: 15px;">,为&nbsp;GNN&nbsp;的研究和应用再添利器。</span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"><br></span></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"></p><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"></span><span style="color: rgb(136, 136, 136);">论文:</span></p><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="color: rgb(136, 136, 136);">https://arxiv.org/pdf/1903.02428.pdf</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">Yann Lecun&nbsp;也热情推荐了这个工作,称赞它是<strong>一个快速、美观的&nbsp;PyTorch&nbsp;库</strong>,用于几何深度学习&nbsp;(图和其他不规则结构的神经网络)。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">作者声称,<strong>PyG&nbsp;甚至比几个月前&nbsp;NYU、AWS&nbsp;联合开发的图神经网络库 DGL(Deep Graph Library)&nbsp;快了&nbsp;15&nbsp;倍!</strong></span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">作者在论文中写道:“这是一个&nbsp;PyTorch&nbsp;的几何深度学习扩展库,它利用专用的&nbsp;CUDA 内核实现了高性能。它遵循一个简单的消息传递&nbsp;API,将最近提出的大多数卷积和池化层捆绑到一个统一的框架中。所有实现的方法都支持&nbsp;CPU&nbsp;和&nbsp;GPU&nbsp;计算,并遵循一个不可变的数据流范式,该范式支持图结构随时间的动态变化。”</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">PyG&nbsp;已经在&nbsp;MIT&nbsp;许可下发布,可以在&nbsp;GitHub&nbsp;上获取。里面有完整的文档说明,并提供了作为起点的教程和示例。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">地址:</span></p><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">https://github.com/rusty1s/pytorch_geometric</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><section style="border-width: 0px;border-style: initial;border-color: initial;clear: both;box-sizing: border-box;" class="tn-Powered-by-XIUMI"><section style="padding: 8px;border-left: 6px solid rgb(255, 202, 0);font-size: 112.5%;line-height: 1.4;font-family: inherit;font-weight: bold;text-decoration: inherit;color: rgb(10, 10, 10);border-top-color: rgb(255, 202, 0);border-right-color: rgb(255, 202, 0);border-bottom-color: rgb(255, 202, 0);box-sizing: border-box;" class="tn-Powered-by-XIUMI"><section class="tn-Powered-by-XIUMI">PyTorch Geometry:基于&nbsp;PyTorch&nbsp;的几何深度学习扩展库</section></section></section><p><br></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;text-align:="" justify;"=""></span><br></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;text-align:="" justify;"="">PyTorch Geometry&nbsp;是一个基于&nbsp;PyTorch&nbsp;的几何深度学习扩展库,用于不规则结构输入数据,例如图&nbsp;(graphs)、点云&nbsp;(point clouds)&nbsp;和流形&nbsp;(manifolds)。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">PyTorch Geometry&nbsp;包含了各种针对图形和其他不规则结构的深度学习方法,也称为几何深度学习,来自于许多已发表的论文。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">此外,它还包含一个易于使用的&nbsp;mini-batch&nbsp;加载器、多&nbsp;GPU&nbsp;支持、大量通用基准数据集和有用的转换,既可以学习任意图形,也可以学习&nbsp;3D&nbsp;网格或点云。</span></p><p class=""><br></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">在&nbsp;PyG&nbsp;中&nbsp;,&nbsp;我们用一个节点特征矩阵</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">和一个稀疏邻接元组</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">代表一个图</span></p><p style="text-align: center;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><br></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">其中</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">以坐标</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">格式编码索引,</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">保持&nbsp;D&nbsp;维边缘特征。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">所有面向用户的&nbsp;API,据加载例程、多&nbsp;GPU&nbsp;支持、数据增强或模型实例化都很大程度上受到&nbsp;PyTorch&nbsp;的启发,以便使它们尽可能保持熟悉。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">Neighborhood Aggregation:</span></strong><span style="letter-spacing: 0.5px;font-size: 15px;">将卷积算子推广到不规则域通常表示为一个邻域聚合(neighborhood aggregation),或&nbsp;message passing scheme (Gilmer et al., 2017)。</span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><br></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">其中,</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">表示一个可微分的置换不变函数,例如&nbsp;sum, mean or max,而</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">和</span><span helvetica="" neue",="" "pingfang="" sc",="" "hiragino="" sans="" gb",="" "microsoft="" yahei="" ui",="" yahei",="" arial,="" sans-serif;font-size:="" 15px;letter-spacing:="" 0.5px;"="">表示可微分函数,例如&nbsp;MLP。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">在实践中,这可以通过收集和散布节点特性并利用&nbsp;broadcasting&nbsp;进行和的element-wise&nbsp;计算来实现,如图&nbsp;1&nbsp;所示。虽然处理的是不规则结构的输入,但这种方案可以通过&nbsp;GPU&nbsp;大大加速。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;text-align: center;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">图&nbsp;1</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">几乎所有最近提出的邻域聚合函数可以利用这个接口,已经集成到&nbsp;PyG&nbsp;的方法包括&nbsp;(但不限于):</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">对于任意图形学习,我们已经实现了:</span></p><ul class=" list-paddingleft-2"><li><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">GCN</span></strong><span style="letter-spacing: 0.5px;font-size: 15px;"> (Kipf &amp; Welling, 2017)&nbsp;和它的简化版本&nbsp;<strong>SGC</strong> (Wu et al., 2019)</span></p></li><li><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">spectral chebyshev&nbsp;和&nbsp;<strong>ARMA</strong> filter convolutionss (Defferrard et al., 2016; Bianchi et al., 2019)</span></p></li><li><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">GraphSAGE</span></strong><span style="letter-spacing: 0.5px;font-size: 15px;"> (Hamilton et al., 2017)</span></p></li><li><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">attention-based operators <strong>GAT</strong> (Veličković et al., 2018)&nbsp;及&nbsp;AGNN (Thekumparampil et al., 2018),</span></p></li><li><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">Graph Isomorphism Network (<strong>GIN</strong>) from Xu et al. (2019)</span></p></li><li><p style="line-height: 1.75em; margin-left: 8px; margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">Approximate Personalized Propagation of Neural Predictions (<strong>APPNP</strong>) operator (Klicpera et al., 2019)</span></p></li></ul><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">对于学习具有多维边缘特征的点云,流形和图,我们提供了:</span></p><ul class=" list-paddingleft-2"><li><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">Schlichtkrull et al. (2018)&nbsp;的&nbsp;relational <strong>GCN</strong> operator</span></p></li><li><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">PointNet++ </span></strong><span style="letter-spacing: 0.5px;font-size: 15px;">(Qi et al., 2017)</span></p></li><li><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">PointCNN</span></strong><span style="letter-spacing: 0.5px;font-size: 15px;"> (Li et al., 2018)</span></p></li><li><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">kernel-based methods <strong>MPNN</strong> (Gilmer et al., 2017),</span></p></li><li><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">MoNet</span></strong><span style="letter-spacing: 0.5px;font-size: 15px;"> (Monti et al., 2017)</span></p></li><li><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">SplineCNN</span></strong><span style="letter-spacing: 0.5px;font-size: 15px;"> (Fey et al., 2018)</span></p></li><li><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">以及边缘卷积算子&nbsp;<strong>EdgeCNN</strong> (Wang et al., 2018b).</span></p></li></ul><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><section style="border-width: 0px;border-style: initial;border-color: initial;clear: both;box-sizing: border-box;" class="tn-Powered-by-XIUMI"><section style="padding: 8px;border-left: 6px solid rgb(255, 202, 0);font-size: 112.5%;line-height: 1.4;font-family: inherit;font-weight: bold;text-decoration: inherit;color: rgb(10, 10, 10);border-top-color: rgb(255, 202, 0);border-right-color: rgb(255, 202, 0);border-bottom-color: rgb(255, 202, 0);box-sizing: border-box;" class="tn-Powered-by-XIUMI"><section class="tn-Powered-by-XIUMI" style="box-sizing: border-box;">实验评估</section></section><section style="width: 0px;height: 0px;clear: both;"></section></section><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><br></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">我们通过对同类评估场景进行综合比较研究,评估了利用&nbsp;PyG&nbsp;所实现方法的正确性。所有使用过的数据集的描述和统计可以在论文附录中找到。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">对于所有的实验,我们都尽可能地遵循各自原始论文的超参数设置,GitHub&nbsp;存储库中提供了复制所有实验的代码。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;text-align: center;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">表&nbsp;2:图分类的结果</span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;text-align: center;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);"><br></span></p><p style="text-align: center;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;text-align: center;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">表&nbsp;3:点云分类的结果</span></p><p class=""><br></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">我们对多个数据模型对进行了多次实验,并报告了在单个&nbsp;NVIDIA GTX 1080 Ti&nbsp;上获得的整个训练过程的运行情况&nbsp;(表&nbsp;4)。<strong>与&nbsp;Deep Graph Library (DGL)(Wang et al., 2018a)&nbsp;相比,PyG&nbsp;训练模型的速度快了&nbsp;15&nbsp;倍</strong>。</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="text-align: center;margin-left: 8px;margin-right: 8px;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;text-align: center;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">表&nbsp;4:训练&nbsp;runtime&nbsp;比较</span></p><section style="border-width: 0px;border-style: initial;border-color: initial;clear: both;box-sizing: border-box;" class="tn-Powered-by-XIUMI"><section style="padding: 8px;border-left: 6px solid rgb(255, 202, 0);font-size: 112.5%;line-height: 1.4;font-family: inherit;font-weight: bold;text-decoration: inherit;color: rgb(10, 10, 10);border-top-color: rgb(255, 202, 0);border-right-color: rgb(255, 202, 0);border-bottom-color: rgb(255, 202, 0);box-sizing: border-box;" class="tn-Powered-by-XIUMI"><section class="tn-Powered-by-XIUMI" style="box-sizing: border-box;">安装、教程&amp;示例</section></section><section style="width: 0px;height: 0px;clear: both;"></section></section><p class=""><br></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">PyTorch Geometric&nbsp;使实现图卷积网络变得非常容易&nbsp;(请参阅&nbsp;GitHub&nbsp;上的教程)。</span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"><br></span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">例如,这就是实现一个边缘卷积层&nbsp;(edge convolution layer)&nbsp;所需的全部代码:</span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"><br></span></p><section class="code-snippet__fix code-snippet__js"><ul class="code-snippet__line-index code-snippet__js"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul><pre class="code-snippet__js" data-lang="python"><code><span class="code-snippet_outer"><span class="code-snippet__keyword">import</span> torch</span></code><code><span class="code-snippet_outer"><span class="code-snippet__keyword">from</span> torch.nn <span class="code-snippet__keyword">import</span> Sequential <span class="code-snippet__keyword">as</span> Seq, Linear <span class="code-snippet__keyword">as</span> Lin, ReLU</span></code><code><span class="code-snippet_outer"><span class="code-snippet__keyword">from</span> torch_geometric.nn <span class="code-snippet__keyword">import</span> MessagePassing</span></code><code><span class="code-snippet_outer"><br></span></code><code><span class="code-snippet_outer"><span class="code-snippet__keyword">class</span> <span class="code-snippet__title">EdgeConv(MessagePassing)</span>:</span></code><code><span class="code-snippet_outer">    <span class="code-snippet__function"><span class="code-snippet__keyword">def</span> <span class="code-snippet__title">__init__(self, F_in, F_out)</span>:</span></span></code><code><span class="code-snippet_outer">      super(EdgeConv, self).__init__()</span></code><code><span class="code-snippet_outer">      self.mlp = Seq(Lin(<span class="code-snippet__number">2</span> * F_in, F_out), ReLU(), Lin(F_out, F_out))</span></code><code><span class="code-snippet_outer"><br></span></code><code><span class="code-snippet_outer">    <span class="code-snippet__function"><span class="code-snippet__keyword">def</span> <span class="code-snippet__title">forward(self, x, edge_index)</span>:</span></span></code><code><span class="code-snippet_outer">      <span class="code-snippet__comment"># x has shape </span></span></code><code><span class="code-snippet_outer">      <span class="code-snippet__comment"># edge_index has shape </span></span></code><code><span class="code-snippet_outer">      <span class="code-snippet__keyword">return</span> self.propagate(aggr=<span class="code-snippet__string">'max'</span>, edge_index=edge_index, x=x)<span class="code-snippet__comment"># shape </span></span></code><code><span class="code-snippet_outer"><br></span></code><code><span class="code-snippet_outer">    <span class="code-snippet__function"><span class="code-snippet__keyword">def</span> <span class="code-snippet__title">message(self, x_i, x_j)</span>:</span></span></code><code><span class="code-snippet_outer">      <span class="code-snippet__comment"># x_i has shape </span></span></code><code><span class="code-snippet_outer">      <span class="code-snippet__comment"># x_j has shape </span></span></code><code><span class="code-snippet_outer">      edge_features = torch.cat(, dim=<span class="code-snippet__number">1</span>)<span class="code-snippet__comment"># shape </span></span></code><code><span class="code-snippet_outer">      <span class="code-snippet__keyword">return</span> self.mlp(edge_features)<span class="code-snippet__comment"># shape </span></span></code></pre></section><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"></span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">此外,与其他深度图神经网络库相比,PyTorch Geometric&nbsp;的速度更快:</span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"><br></span></p><p style="text-align: center;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;text-align: center;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">表:在一块&nbsp;NVIDIA GTX 1080Ti&nbsp;上的训练&nbsp;runtime</span></p><p class=""><br></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="color: rgb(255, 104, 39);"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">安装</span></strong></span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">确保至少安装了&nbsp;PyTorch 1.0.0,并验证</span><span style="letter-spacing: 0.5px;font-size: 15px;background-color: rgb(214, 214, 214);">&nbsp;cuda/bin</span><span style="letter-spacing: 0.5px;font-size: 15px;">&nbsp;和&nbsp;</span><span style="letter-spacing: 0.5px;font-size: 15px;background-color: rgb(214, 214, 214);">cuda/include</span><span style="letter-spacing: 0.5px;font-size: 15px;">&nbsp;分别位于&nbsp;</span><span style="letter-spacing: 0.5px;font-size: 15px;background-color: rgb(214, 214, 214);">$PATH</span><span style="letter-spacing: 0.5px;font-size: 15px;">&nbsp;和 </span><span style="letter-spacing: 0.5px;font-size: 15px;background-color: rgb(214, 214, 214);">$cpathrespecific</span><span style="letter-spacing: 0.5px;font-size: 15px;">,例如:</span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><section class="code-snippet__fix code-snippet__js"><ul class="code-snippet__line-index code-snippet__js"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul><pre class="code-snippet__js" data-lang="ruby"><code><span class="code-snippet_outer">$ python -c <span class="code-snippet__string">"import torch; print(torch.__version__)"</span></span></code><code><span class="code-snippet_outer"><span class="code-snippet__meta">&gt;&gt;</span>&gt; <span class="code-snippet__number">1.0</span>.<span class="code-snippet__number">0</span></span></code><code><span class="code-snippet_outer"><br></span></code><code><span class="code-snippet_outer">$ echo $PATH</span></code><code><span class="code-snippet_outer"><span class="code-snippet__meta">&gt;&gt;</span>&gt; <span class="code-snippet__regexp">/usr/local/cuda/bin:</span>...</span></code><code><span class="code-snippet_outer"><br></span></code><code><span class="code-snippet_outer">$ echo $CPATH</span></code><code><span class="code-snippet_outer"><span class="code-snippet__meta">&gt;&gt;</span>&gt; <span class="code-snippet__regexp">/usr/local/cuda/include:</span>...</span></code></pre></section><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;">然后运行:</span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"><br></span></p><section class="code-snippet__fix code-snippet__js"><ul class="code-snippet__line-index code-snippet__js"><li></li><li></li><li></li><li></li><li></li></ul><pre class="code-snippet__js" data-lang="sql"><code><span class="code-snippet_outer">$ pip <span class="code-snippet__keyword">install</span> <span class="code-snippet__comment">--upgrade torch-scatter</span></span></code><code><span class="code-snippet_outer">$ pip <span class="code-snippet__keyword">install</span> <span class="code-snippet__comment">--upgrade torch-sparse</span></span></code><code><span class="code-snippet_outer">$ pip <span class="code-snippet__keyword">install</span> <span class="code-snippet__comment">--upgrade torch-cluster</span></span></code><code><span class="code-snippet_outer">$ pip <span class="code-snippet__keyword">install</span> <span class="code-snippet__comment">--upgrade torch-spline-conv (optional)</span></span></code><code><span class="code-snippet_outer">$ pip <span class="code-snippet__keyword">install</span> torch-geometric</span></code></pre></section><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"></span></p><p class=""><br style="max-width: 100%; box-sizing: border-box !important;"></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="color: rgb(255, 104, 39);"><strong><span style="letter-spacing: 0.5px;font-size: 15px;">运行示例</span></strong></span></p><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><span style="letter-spacing: 0.5px;font-size: 15px;"><br></span></p><section class="code-snippet__fix code-snippet__js"><ul class="code-snippet__line-index code-snippet__js"><li></li><li></li></ul><pre class="code-snippet__js" data-lang="properties"><code><span class="code-snippet_outer"><span class="code-snippet__attr">cd</span> <span class="code-snippet__string">examples</span></span></code><code><span class="code-snippet_outer"><span class="code-snippet__attr">python</span> <span class="code-snippet__string">cora.py</span></span></code></pre></section><p style="line-height: 1.75em;margin-left: 8px;margin-right: 8px;"><br></p><p style="margin-right: 8px; margin-left: 8px; line-height: 1.75em;"><span style="color: rgb(136, 136, 136);">paper:</span></p><p style="margin-right: 8px; margin-left: 8px; line-height: 1.75em;"><span style="color: rgb(136, 136, 136);">https://arxiv.org/pdf/1903.02428.pdf</span></p><p style="margin-right: 8px; margin-left: 8px; line-height: 1.75em;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">GitHub:</span></p><p style="margin-right: 8px; margin-left: 8px; line-height: 1.75em;"><span style="letter-spacing: 0.5px; color: rgb(136, 136, 136);">https://github.com/rusty1s/pytorch_geometric</span></p><p><br></p><p style="margin-right: 8px; margin-left: 8px; line-height: 1.75em;"><span style="color: rgb(136, 136, 136);"><br></span><br></p><p></p>
页: [1]
查看完整版本: LeCun推荐:最新PyTorch图神经网络库,速度快15倍(GitHub+论文)