栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Windows下torch

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Windows下torch

学习GNN的时候尝试在线安装torch_geometric ,自己安装过程中出现了挺多问题,找到官网后按照其指示最后成功在线安装(官网链接:torch-geometric · PyPI )

以下是我的安装流程:

先激活环境:

conda activate py37

由于我安装的是:PyTorch 1.10.0,故需要执行以下的操作:

pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cpu.html
pip install torch-sparse -f https://data.pyg.org/whl/torch-1.10.0+cpu.html
pip install torch-geometric

按照官网上的说明,以下为选择性安装部分(torch-cluster和torch-spline-conv):

pip install torch-cluster -f https://data.pyg.org/whl/torch-1.10.0+cpu.html
pip install torch-spline-conv -f https://data.pyg.org/whl/torch-1.10.0+cpu.html

 

 

最后我们测试一下是否成功安装:

测试代码如下:(直接利用官网上提供的测试代码)

import torch
from torch import Tensor
from torch.nn import Sequential, Linear, ReLU
from torch_geometric.nn import MessagePassing

class EdgeConv(MessagePassing):
    def __init__(self, in_channels, out_channels):
        super().__init__(aggr="max")  # "Max" aggregation.
        self.mlp = Sequential(
            Linear(2 * in_channels, out_channels),
            ReLU(),
            Linear(out_channels, out_channels),
        )

    def forward(self, x: Tensor, edge_index: Tensor) -> Tensor:
        # x: Node feature matrix of shape [num_nodes, in_channels]
        # edge_index: Graph connectivity matrix of shape [2, num_edges]
        return self.propagate(edge_index, x=x)  # shape [num_nodes, out_channels]

    def message(self, x_j: Tensor, x_i: Tensor) -> Tensor:
        # x_j: Source node features of shape [num_edges, in_channels]
        # x_i: Target node features of shape [num_edges, in_channels]
        edge_features = torch.cat([x_i, x_j - x_i], dim=-1)
        return self.mlp(edge_features)  # shape [num_edges, out_channels]

运行结果如下:

Bingo! 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/725885.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号