1. 使用命令 tf.config.list_physical_devices('GPU') 检查GPU是否可用
遇到的问题:
Could not load dynamic library 'libcusolver.so.10'; dlerror: libcusolver.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/ros/melodic/lib:/usr/local/cuda-11.1/lib64
解决办法:
>>> sudo gedit /etc/profile
在文件最后加上代码:
export PATH=/usr/local/cuda-11.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH
>>> source /etc/profile
重新运行命令检查GPU是否可用,大功告成!
2. 安装tensorflow2之后导致tensorflow1的某些模块不可用的情况
解决办法举例:
原代码:
test_in_tensor = tf.placeholder(dtype=tf.float32, shape=[1, 256, 512, 3], name='input')
报错:
AttributeError: module 'tensorflow' has no attribute 'placeholder'
改成:
tf.compat.v1.disable_eager_execution()
test_in_tensor = tf.compat.v1.placeholder(dtype=tf.float32, shape=[1, 256, 512, 3], name='input')
3. 某些函数已经完全改变,如何找到现有的表达方式
例如:使用问题2的解决办法解决了问题:
AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’
又引入了下列问题:
AttributeError: module ‘tensorflow.compat.v1’ has no attribute ‘contrib’
比如我的出问题代码为:
w_init = tf.compat.v1.contrib.layers.variance_scaling_initializer()
那么在下述网站上进行搜索variance_scaling_initializer()。Tensorflowhttps://tensorflow.google.cn/api_docs/python/tf/all_symbols找到以下结果:
那么我们就将代码改成:
w_init = tf.compat.v1.variance_scaling_initializer()