Tensorflow2.1学习-1-安装

1、首先安装实验环境,需要python3.7(默认安装了conda)

conda create -n TF2.1 python=3.7

conda activate TF2.1,进入环境

conda install cudatoolkit=10.1

安装不顺畅可以在网上搜conda换源

conda install cudnn=7.6

pip install tensorflow==2.1

2、启动pycharm

可以直接在csdn上搜pycharm安装包,社区版的就行。

点击New Project,选择interpreter为TF2.1

然后进行检测。先建立一个test.py文件,输入如下代码

import tensorflow as tf

tensorflow_version = tf.__version__
gpu_available = tf.test.is_gpu_available()

print("tensorflow version:", tensorflow_version, "\tGPU available:", gpu_available)

a = tf.constant([1.0, 2.0],name = "a")
b = tf.constant([1.0, 2.0],name = "b")
result = tf.add(a, b, name = "add")
print(result)

出错了:TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower. 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).这个错误通常意味着项目中使用的TensorFlow版本与protobuf库版本不兼容。

pip install --upgrade protobuf>=3.19.0

解决

安装成功了,但是不能用GPU,在网上搜到tensorflow需要cuda10.1或者11.0的,而我安装的是11.8的,进行卸载安装。

参考博客windows下CUDA的卸载以及安装_把电脑上的cuda卸载了会有影响么-CSDN博客

CUDA安装及环境配置——最新详细版-CSDN博客

成功,换成了cuda11.0.1

  • 8
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值