tensorflow 1.x和3090、cuda部署

这里写目录标题

3090、cuda和tensorflow 1.x

因为3090只支持cuda11.0+的版本,而tensorflow1.×已经不再维护,没有出支持cuda11.0+的版本了。
nvidia提供了TF1.x对RTX 3090、cuda11等新硬件的支持。卸载已有的tensorflow-gpu包和conda安装的cuda包,安装nvidia版本tensorflow:

pip install nvidia-pyindex
pip install nvidia-tensorflow  # 会自动安装相关cuda依赖

pip install tensorboard
import tensorflow as tf 和 tf.test.is_gpu_available() 测试,如果出现以下内容WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.此时还需要再安装一个.重新安装tensorboard。pip install tensorboard即可解决

pip install tensorboard
import tensorflow as tf 和 tf.test.is_gpu_available() 测试,如果出现以下内容WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.此时还需要再安装一个。重新安装tensorboard。pip uninstall tensorboard、pip install tensorboard即可解决
注:nvidia-tensorflow仓库提示需要使用Python3.8,但我使用Python3.6,可用。
参考:
https://blog.csdn.net/qq_39543404/article/details/112171851
https://www.cnblogs.com/xikeguanyu/p/16269066.html
https://zhuanlan.zhihu.com/p/521957441
https://blog.csdn.net/znevegiveup1/article/details/115053563

测试TF和cuda

1#(1)查看TF版本
import tensorflow as tf
tf.__version__        # 此命令为获取安装的tensorflow版本
print(tf.__version__) # 输出版本
tf.__path__			   #查看tensorflow安装路径
print(tf.__path__)

#(2)查看cuda是否可用
import tensorflow as tf
print(tf.test.is_gpu_available())#如果结果是True,表示GPU可用

import tensorflow as tf
tf.test.is_gpu_available()

#(3)查看cuda版本
nvidia-smi #系统中自带的cuda

conda list | grep cuda #虚拟环境的cuda或者用pip看包信息


2import tensorflow as tf
gpu_device_name = tf.test.gpu_device_name()
print(gpu_device_name)
tf.test.is_gpu_available()

import tensorflow as tf
tf.test.is_built_with_cuda()
print(tf.test.is_built_with_cuda())#返回true表示可用


3from tensorflow.python.client import device_lib
 # 列出所有的本地机器设备
local_device_protos = device_lib.list_local_devices()
# 打印
print(local_device_protos)
# 只打印GPU设备
[print(x) for x in local_device_protos if x.device_type == 'GPU']

测试Pytorch和cuda

import torch
print(torch.__version__)
print(torch.cuda.is_available())
  • CUDA版本
    1.查看当前安装的版本(nvcc -V)
    通过nvcc(NVIDIA Cuda compiler driver)命令可查看本机安装的CUDA版本:nvcc -V
    nvcc -V查看的是系统自带的cuda的版本,要看虚拟环境中的版本,要导入pytorch和tensorflow库进行测试
    pytorch中:print(torch.__version__)
    tensorflow中:conda list | grep cuda直接在终端里,打开相应环境,进行查看
    2.查看能支持的最高CUDA版本(nvidia-smi)
    通过nvidia-smi 命令可查看本机的Nvidia显卡驱动信息,以及该驱动支持的最高的CUDA版本。nvidia-smi,例如下面的CUDA Version就是我的电脑上面能够安装的最高版本的CUDA,并且该版本号是向下支持的,可以安装低于该版本号的所有CUDA套件

tenserflow卸载
检查:
sudo pip show tensorflow
卸载使用:
pip uninstall protobuf
pip uninstall tensorflow
pip uninstall tensorflow-gpu

pip wheel 安装 TensorRT:
安装 nvidia-pyindex 包用下面这条命令
pip install nvidia-pyindex
安装装好之后,就可以开始安装 TensorRT 了。使用下面的命令:
pip install --upgrade nvidia-tensorrt

pip install nvidia-pyindex
pip install nvidia-tensorrt==8.2.5.1

import tensorrt
print(tensorrt.__version__)
assert tensorrt.Builder(tensorrt.Logger())

参考:https://blog.csdn.net/qq_37541097/article/details/114847600
https://www.cnblogs.com/asnelin/p/15929442.html

同时安装tensorflow、pytorch
主要考虑cudnn、tensorflow、pytorch的版本问题,先选cuda的版本和显卡的匹配,再选tensorflow、pytorch的cuda对应版本。
cuda、cudnn、tensorflow(-gpu)、pytorch弄清版本。
参考:https://blog.csdn.net/LIWEI940638093/article/details/113811563
链接: 版本安装连接link

猜你喜欢

转载自blog.csdn.net/weixin_44986037/article/details/132254050