新配置的tensorflow+GPU提示lib文件打不开,如下:
提示打不开libcublas.so.10.0、libcudart.so.10.0、libcufft.so.10.0、libcurand.so.10.0、libcusolver.so.10.0、libcusparse.so.10.0这6个lib文件。
从/usr/local/cuda-10.1/lib64复制libcublas.so.10、libcudart.so.10.1、libcufft.so.10、libcurand.so.10、libcusolver.so.10、libcusparse.so.10,讲文件名修改为以上形式,再复制到/usr/local/cuda-10.1/lib64,即可。libcublas.so.10没有的话,就在整个硬盘下进行搜索,然后复制和修改。
重新测试代码,参考文章:https://blog.csdn.net/yiyayiya557/article/details/105699305
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
升级到tensorflow2.0以上时,测试代码如下,以tensorflow2.2.0为例,参考https://blog.csdn.net/weixin_38410551/article/details/103631977
import tensorflow as tf
tf.compat.v1.disable_eager_execution() #保证sess.run()能够正常运行
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess= tf.compat.v1.Session()#版本2.0的函数
print(sess.run(c))