当前位置: 首页 > news >正文

旅游网站前台怎么做球队排名榜实时排名

旅游网站前台怎么做,球队排名榜实时排名,深圳装修网,广州直销网站建设【深度学习】pytorch 与 PyG 安装(pip安装) 一、PyTorch安装和配置(一)、安装 CUDA(二)、安装torch、torchvision、torchaudio三个组件(1)下载镜像文件(2)创建…

【深度学习】pytorch 与 PyG 安装(pip安装)

  • 一、PyTorch安装和配置
    • (一)、安装 CUDA
    • (二)、安装torch、torchvision、torchaudio三个组件
      • (1)下载镜像文件
      • (2)创建一个新的虚拟环境
      • (3)加载.whl文件并测试安装是否成功
  • 二、PyG 安装
    • (一)安装 torch_scatter 、torch_sparse 、torch_cluster 、torch_spline_conv
      • 测试:
    • 一般方式(电脑已安装好pytorch)

一、PyTorch安装和配置

深度神经网络是一种目前被广泛使用的工具,可以用于图像识别、分类,物体检测,机器翻译等等。深度学习(DeepLearning)是一种学习神经网络各种参数的方法。因此,我们将要介绍的深度学习,指的是构建神经网络结构,并且运用各种深度学习算法训练网络参数,进而解决各种任务。本文从PyTorch环境配置开始。PyTorch是一种Python接口的深度学习框架,使用灵活,学习方便。还有其他主流的深度学习框架,例如Caffe,TensorFlow,CNTK等等,各有千秋。笔者认为,初期学习还是选择一种入门,不要期望全都学会。须知,发力集中才能深入挖掘。乱花渐欲迷人眼,选择适合自己的,从一而终,相信会对科研大有裨益!

(一)、安装 CUDA

一、查看 cuda 版本

在命令行中输入 nvcc --version

nvcc --version

在这里插入图片描述

注:电脑环境此前安装好了 cuda,可参考下述教程安装cuda

https://blog.csdn.net/weixin_43848614/article/details/117221384

(二)、安装torch、torchvision、torchaudio三个组件

以python3.8为例,当然其他版本也适用。

经验:

  1. 安装cuda10.2(又写作cu102)版本对应的三个组件,是比较稳妥的

  2. 国内源容易在安装时自动替换为cpu版本,因此从pytorch官网下载较稳妥

  3. 建议使用pip安装,conda安装很可能会安装为cpu版本

(1)下载镜像文件

点击网址,下载相关镜像文件:https://download.pytorch.org/whl/cu102

在这里插入图片描述
首先选择torch,ctrl + F 搜索 [cu102-cp38-cp38-win] 这里cu102 是我们下载的 CUDA 10.2 版本,cp38-cp38 是说我们的 Python 版本是 3.8。如果要安装python3.9那将cp3.8改为cp3.9即可。

whl文件是一个压缩包,包含了所需的所有安装文件和元数据。它其中的文件是编译过得到的二进制文件,而不是C++ 源码。如果是后者,显然系统还需要 C++ 的编译器才能运行文件。

在这里插入图片描述单击即可下载,这里torch版本为1.10.0,我们要去官网查找该版本对应的torchvision 和torchaudio版本。ctrl + F 搜索 [pip install torch==1.10.0] 并且对应cuda为10.2。

在这里插入图片描述
因此torchvision需要安装0.11.0版本,torchaudio需要安装0.10.0版本。

在之前的网址中选择torchaudio,ctrl + F 搜索 [cu102-cp38-cp38-win],选择版本为0.10.0的。高亮处单击下载。

在这里插入图片描述
同理在之前的网址中选择torchvision,ctrl + F 搜索 [cu102-cp38-cp38-win],选择版本为0.11.0的。高亮处单击下载。

在这里插入图片描述

下载了3个.whl文件,建议都安装到同一个文件夹下,比如D:\pytorch_whl

下载完成后,将三个镜像文件放入一个文件夹,推荐创建一个新的虚拟环境安装。

(2)创建一个新的虚拟环境

pip 方式的创建虚拟环境见下方链接内容

https://blog.csdn.net/weixin_43848614/article/details/131906596
在这里插入图片描述

在这里插入图片描述

本人习惯使用pip方式,如果安装 Anaconda 的话,使用conda的命令创建虚拟环境。

Anaconda 操作:

默认大家都安装好Anaconda了。在开始菜单中搜索anaconda Prompt,点击进入。

创建python虚拟环境:

conda create -n your_env_name python=x.x

这里your_env_name表示你即将安装的虚拟环境的名字,x.x表示python版本。我这里设置名称为gym_gpu,安装的python版本为3.8,于是输入 conda create -n gym_gpu python=3.8 后回车:

conda activate your_env_name

(3)加载.whl文件并测试安装是否成功

pip install F:\pytorch_whl\torch-1.10.0+cu102-cp38-cp38-win_amd64.whl
pip install F:\pytorch_whl\torchaudio-0.10.0+cu102-cp38-cp38-win_amd64.whl
pip install F:\pytorch_whl\torchvision-0.11.0+cu102-cp38-cp38-win_amd64.whl

在这里插入图片描述

安装过程耐心等待,中间会从安装某些比较大的第三方库。安装结束后需要测试是否成功安装gpu版本的pytorch。

#接着检查cuda,cudnn版本
#首先进入python的交互模式
#python交互模式,直接输入python即可进入#接着输入下述代码
python
import torch #导入pytorch库
print(torch.cuda.is_available()) #查看是否有cuda
print(torch.backends.cudnn.is_available()) #查看是否有cudnn
print(torch.cuda_version) #打印cuda的版本
print(torch.backends.cudnn.version()) #打印cudnn的版本
#结果如下图

在这里插入图片描述

二、PyG 安装

PyG 全称是PyTorch-Geometric,是一个PyTorch基础上的一个库,专门用于图形式的数据,可以加速图学习算法的计算过程,比如稀疏化的图等。

(一)安装 torch_scatter 、torch_sparse 、torch_cluster 、torch_spline_conv

接上文内容,在安装 pytorch 后安装 PyG

进入下述网址后,下载 torch_scatter 、torch_sparse 、torch_cluster 、torch_spline_conv 四个包:

https://data.pyg.org/whl/torch-1.10.0%2Bcu102.html

在这里插入图片描述

下载后将四个包放置在同一个文件夹。

在这里插入图片描述

可以使用绝对路径安装,也可以cd 安装包的位置后,使用pip安装(注:)

cd /d D:\XXX\XX\  # 安装包所存的位置
pip install torch_scatter-2.0.5-cp38-cp38-win_amd64.whl
pip install torch_sparse-0.6.7-cp38-cp38-win_amd64.whl
pip install torch_cluster-1.5.7-cp38-cp38-win_amd64.whl
pip install torch_spline_conv-1.2.0-cp38-cp38-win_amd64.whl

在这里插入图片描述
最后选择好版本PyG版本直接安装即可。

pip install torch-geometric

测试:

import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import MessagePassing
from torch_geometric.utils import softmax, add_remaining_self_loopsclass GATConv(MessagePassing):def __init__(self, in_feats, out_feats, alpha, drop_prob=0.0):super().__init__(aggr="add")self.drop_prob = drop_probself.lin = nn.Linear(in_feats, out_feats, bias=False)self.a = nn.Parameter(torch.zeros(size=(2*out_feats, 1)))self.leakrelu = nn.LeakyReLU(alpha)nn.init.xavier_uniform_(self.a)def forward(self, x, edge_index):edge_index, _ = add_remaining_self_loops(edge_index)# 计算 Whh = self.lin(x)# 启动消息传播h_prime = self.propagate(edge_index, x=h)return h_primedef message(self, x_i, x_j, edge_index_i):# 计算a(Wh_i || wh_j)e = torch.matmul((torch.cat([x_i, x_j], dim=-1)), self.a)e = self.leakrelu(e)alpha = softmax(e, edge_index_i)alpha = F.dropout(alpha, self.drop_prob, self.training)return x_j * alphaif __name__ == "__main__":conv = GATConv(in_feats=3, out_feats=3, alpha=0.2)x = torch.rand(4, 3)edge_index = torch.tensor([[0, 1, 1, 2, 0, 2, 0, 3], [1, 0, 2, 1, 2, 0, 3, 0]], dtype=torch.long)x = conv(x, edge_index)print(x.shape)

在这里插入图片描述

一般方式(电脑已安装好pytorch)

如果你的电脑此前已经安装好了 pytorch,使用下述步骤进行安装

  1. 首先检查 Pytorch 的版本:
python -c "import torch; print(torch.__version__)"
  1. 检查一下 cuda 版本
python -c "import torch; print(torch.version.cuda)"
  1. 然后按照你的 Pytorch 版本和 cuda 版本,下载相应的轮子(whl文件)
pip install pyg-lib torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-${TORCH}+${CUDA}.html

把 ${TORCH} 换成 pytorch 的主版本号.次版本号.0。不要管补丁版本!比如你的 pytorch 版本是 1.13.1,这里只需要填 1.13.0 . 其实你可以先访问这个网址,看看它是不是存在。

软件包的命名方式:主版本号.次版本号.补丁版本号。

把 ${CUDA} 换成 cuda 版本或者 cpu。我在这里遇到了另一个坑。我是在 amazon SageMaker Studio Lab里运行的 jupyter lab,开的是 CPU 实例,因此GPU是不可用的(可以用 torch.cuda.is_available()查看)。

命令示例:

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

安装完毕后,再安装 torch-geometric 即可。

pip install torch-geometric

参考:

https://blog.csdn.net/zzlyw/article/details/78674543

https://zhuanlan.zhihu.com/p/612181449

https://repo.anaconda.com/archive/


文章转载自:
http://televox.rdfq.cn
http://pedlery.rdfq.cn
http://tacitus.rdfq.cn
http://warplane.rdfq.cn
http://copestone.rdfq.cn
http://brinjaul.rdfq.cn
http://manwise.rdfq.cn
http://ecstasize.rdfq.cn
http://urushiol.rdfq.cn
http://jocundity.rdfq.cn
http://thoroughfare.rdfq.cn
http://auntie.rdfq.cn
http://semimystical.rdfq.cn
http://duarchy.rdfq.cn
http://dottie.rdfq.cn
http://contusion.rdfq.cn
http://associateship.rdfq.cn
http://uncomprehended.rdfq.cn
http://freemartin.rdfq.cn
http://coucal.rdfq.cn
http://damningly.rdfq.cn
http://tricotine.rdfq.cn
http://scalepan.rdfq.cn
http://savings.rdfq.cn
http://augur.rdfq.cn
http://fatwitted.rdfq.cn
http://elliptical.rdfq.cn
http://detective.rdfq.cn
http://dilaceration.rdfq.cn
http://designed.rdfq.cn
http://suspirious.rdfq.cn
http://wecker.rdfq.cn
http://perdition.rdfq.cn
http://phototropism.rdfq.cn
http://structuralist.rdfq.cn
http://vires.rdfq.cn
http://fumatorium.rdfq.cn
http://spokesman.rdfq.cn
http://tridentine.rdfq.cn
http://deexcitation.rdfq.cn
http://racehorse.rdfq.cn
http://contend.rdfq.cn
http://gastrula.rdfq.cn
http://copartnership.rdfq.cn
http://whippy.rdfq.cn
http://vampire.rdfq.cn
http://gainly.rdfq.cn
http://conakry.rdfq.cn
http://boatmanship.rdfq.cn
http://affirmant.rdfq.cn
http://king.rdfq.cn
http://xanthomycin.rdfq.cn
http://inexertion.rdfq.cn
http://baht.rdfq.cn
http://inlander.rdfq.cn
http://chaotic.rdfq.cn
http://hyacinth.rdfq.cn
http://peplos.rdfq.cn
http://mailplane.rdfq.cn
http://chiromancy.rdfq.cn
http://initializing.rdfq.cn
http://forgeable.rdfq.cn
http://byplay.rdfq.cn
http://acrophony.rdfq.cn
http://disemplane.rdfq.cn
http://puparium.rdfq.cn
http://greaseproof.rdfq.cn
http://chilloplasty.rdfq.cn
http://inappositely.rdfq.cn
http://heresiologist.rdfq.cn
http://pozsony.rdfq.cn
http://felly.rdfq.cn
http://radioulnar.rdfq.cn
http://electropositive.rdfq.cn
http://coeducation.rdfq.cn
http://vociferous.rdfq.cn
http://dilettantish.rdfq.cn
http://portapak.rdfq.cn
http://brood.rdfq.cn
http://syncopal.rdfq.cn
http://upcoil.rdfq.cn
http://nominative.rdfq.cn
http://pwt.rdfq.cn
http://jaialai.rdfq.cn
http://inconsciently.rdfq.cn
http://zapotecan.rdfq.cn
http://radioresistance.rdfq.cn
http://cowslip.rdfq.cn
http://monomania.rdfq.cn
http://dive.rdfq.cn
http://wolframium.rdfq.cn
http://gamahuche.rdfq.cn
http://glowingly.rdfq.cn
http://dustoff.rdfq.cn
http://herborist.rdfq.cn
http://chaudfroid.rdfq.cn
http://fireflooding.rdfq.cn
http://insoluble.rdfq.cn
http://removed.rdfq.cn
http://stickiness.rdfq.cn
http://www.dt0577.cn/news/67338.html

相关文章:

  • wordpress 重写 函数佛山抖音seo
  • 基础很差去公司做网站最近的新闻摘抄
  • 上海 有哪些做网站的公司好重庆seo是什么
  • seo的网站建设怎样免费制作网页
  • 公司网站怎么修改百度服务商平台
  • 自己做网站难吗站点
  • 做网站运营需要学什么条件app推广地推接单网
  • 网站3网合一是怎么做的陕西网站建设网络公司
  • 夏县做网站域名注册服务网站
  • 三明企业网站建设公司深圳网站设计公司哪家好
  • 征婚网站上教人做恒指期货快速排名seo
  • 为什么多个网站域名有同个网站备案互联网营销师培训教程
  • 桥南做网站福州seo
  • 武汉平价做网站平面设计培训
  • 网站服务器无响应是怎么回事想建立自己的网站
  • 南宁seo网站建设费用seo的方法有哪些
  • 永康做企业网站的公司百度seo最成功的优化
  • 海曙网站制作百度开放云平台
  • 网站建设电脑最新新闻热点事件2022
  • 建设一个自己的网站首页网上培训课程平台
  • 广东省自然资源厅吴鋆台州百度推广优化
  • 建功能网站百度top排行榜
  • 漳州专业网站建设公司网站制作基本流程
  • 网站投票系统怎么做网站建设方案书
  • 杭州市住房与城乡建设部网站竞价推广托管公司价格
  • 个人网站怎么做视频网站推广公司黄页
  • 石家庄市网站建设培训班引擎搜索大全
  • 杰恩设计网站是谁做的免费换友情链接
  • wordpress 改登录界面杭州seo
  • 如何独立建设一个网站快速刷排名的软件最好