Pycharm异常管理(七)TensorFlow2.1.0(CPU版)警告信息:Could not load dynamic library 'cudart64_101.dll'; dlerror: ...

第一章、异常问题

        跑一个AI算法之前的版本基本信息:

       然后跑下面的程序:

# import numpy as np
import tensorflow as tf

print("hello world")
w = tf.Variable(0.0, dtype=tf.float32)
cost = tf.add(tf.add(w**2, tf.multiply(-10., w)), 25)
train = tf.train.GradientDescentOptimizer(0.01).minimize(cost)

init = tf.global_variables_initializer()
session = tf.Session()
session.run(init)
print(session.run(w))

session.run(train)
print(session.run(w))

for i in range(1000):
    session.run(train)
print(session.run(w))


      警告信息、错误信息如下:

第二章、异常信息

"D:\Program Files\Python37\python.exe" E:/PycharmProjects/3-11TesorFlow/sources/test.py
 2020-04-18 09:57:07.670145: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
 2020-04-18 09:57:07.680411: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
 hello world
 2020-04-18 09:57:22.186079: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
 2020-04-18 09:57:22.186320: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)
 2020-04-18 09:57:22.194163: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-5FDTSAD
 2020-04-18 09:57:22.194599: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-5FDTSAD
 2020-04-18 09:57:22.206499: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
 Traceback (most recent call last):
   File "E:/PycharmProjects/3-11TesorFlow/sources/test.py", line 7, in 
     train = tf.train.GradientDescentOptimizer(0.01).minimize(cost)
 AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'GradientDescentOptimizer'
 Process finished with exit code 1



第三章、异常原因

      • 警告信息——跑TensorFlow算法需要cudart64_101.dll、nvcuda.dll等,此前,我pycharm没有安装相关的支持软件,导致出错。
      • 错误信息——由于版本tensorFlow-cpu2.1.0升级了,模块

    GradientDescentOptimizer是存在的,但是tensorFlow-cpu2.1.0语法改变了导致找不到模块。

第四章、异常解决

4.1、 警告信息的解决方法

  • 显卡不支持GPU,警告信息可以忽略它。
  • 若你的显卡支持GPU,可以在这里解决掉警告信息。我们参考下面的这篇非常非常非常非常非常非常非常非常非常非常非常非常非常详细的文章来解决跑TensorFlow算法所有需要安装的软件包。

4.2、 错误信息

       换言之,显卡只支持CPU计算的情况下,也就是我现在遇到的情况。解决方法:

import numpy as np
# import tensorflow as tf  # 旧版本的语法
import tensorflow.compat.v1 as tf  # TensorFlow2.1.0版本的语法

tf.compat.v1.disable_eager_execution()  # 必须要这行,否者会发生错误信息: RuntimeError: `loss` passed to Optimizer.compute_gradients should be a function when eager execution is enabled.
print("hello world")
w = tf.Variable(0.0, dtype=tf.float32)
cost = tf.add(tf.add(w**2, tf.multiply(-10., w)), 25)
train = tf.train.GradientDescentOptimizer(0.01).minimize(cost)

init = tf.global_variables_initializer()
# session = tf.Session() # 旧版本的语法
session = tf.compat.v1.Session()  # TensorFlow2.1.0版本的语法
session.run(init)
print(session.run(w))

session.run(train)
print(session.run(w))

for i in range(1000):
    session.run(train)
print(session.run(w))



'''
# 参考demo,以便解决tf.Session()问题
import tensorflow as tf
tf.compat.v1.disable_eager_execution()  # 必须要这行,否者会发生错误信息: untimeError: The Session graph is empty.  Add operations to the graph before calling run().
hello = tf.constant('hello,tensorflow')
sess= tf.compat.v1.Session()
print(sess.run(hello))
'''









  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我爱AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值