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

win11部署Torch,tf-GPU环境(复现文章Requests)

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

win11部署Torch,tf-GPU环境(复现文章Requests)

需求1:在win11指定文件夹中安装torch环境, torch需求版本见官网,受CUDA版本限制,详见torch.org

默认已经安装 Anaconda3,可以使用conda指令
1.在指定 文件夹下进入cmd(或在CMD中CD到指定文件夹)
2.在CMD中用conda指令创建环境(环境名为env_name),并指定Python版本:

conda create -n env_name python=3.x

3.进入创建的环境:

conda activate env_name

4.在该环境下安装torch包,此处指令参照torch.org官网:
如CUDA版本为11.1以上,则可安装torch1.8GPU版:

 # CUDA 11.1
 conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge

5.安装完成后在Pycharm中添加该环境的路径,路径地址如:
“D:SoftwareAnaconda3envstfpython.exe”

备注:
在CMD退出环境:conda deactivate
     删除环境:conda remove -n env_name
环境测试:
import torch

print("torch版本号:", end="")
print(torch.__version__)
print("判断torch是否可用:", end="")
print(torch.cuda.is_available())

print("gpu数量:", end="")
print(torch.cuda.device_count())

print("gpu名字,设备索引默认从0开始:", end="")
print(torch.cuda.get_device_name(0))
print("现在正在使用的GPU编号:", end="")
print(torch.cuda.current_device())

------------------------我是分割线-------------------------------------

需求2:在win11安装tf-gpu版本

1.用conda创建虚拟环境,同时指定Python版本:

#Python版本要求与tf版本相对应
#详见tf官网:https://tensorflow.google.cn/install/source_windows#gpu
conda create -n tf1.14 python=3.7

2.查看有哪些版本可以安装:

conda search tensorflow-gpu

3.在创建的虚拟环境中安装TensorFlow-GPU版:
conda install tensorflow-gpu==1.14.0

import tensorflow as tf

print(tf.__version__)
print(tf.__path__)
print(tf.__operators__)

print(tf.config.list_physical_devices('GPU'))
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/504056.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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