tf1.15 使用过程中的一些坑

文章目录

    • 安装tf1.x中的一些注意事项
      • 使用时有错,先把跟包版本有关的列出来:
        • 提示无scipy.misc:
        • ModuleNotFoundError: No module named ‘tensorflow.python.types‘
        • TypeError: batch_normalization() got an unexpected keyword argument 'decay'
        • Process finished with exit code -1073741819 (0xC0000005) --OOM
    • 一次迁移实操

安装tf1.x中的一些注意事项

参考2021最新:TensorFlow各个GPU版本CUDA和cuDNN对应版本整理(最简洁)

Version Python version Compiler Build tools cuDNN CUDA
tensorflow_gpu-1.15.0 3.5-3.7 MSVC 2017 Bazel 0.26.1 7.4 10
tensorflow_gpu-1.14.0 3.5-3.7 MSVC 2017 Bazel 0.24.1-0.25.2 7.4 10
tensorflow_gpu-1.13.0 3.5-3.7 MSVC 2015 update 3 Bazel 0.19.0-0.21.0 7.4 10

tf1.15 使用过程中的一些坑_第1张图片

以下解决方案,基于版本tf1.X最高版
首先当然是安装Nvidia的CUDA 和 cudnn
还可参考:
配置tensorflow-GPU(1.x)环境
tensorflow对应cuda的兼容版本问题
最后,安装好后检测tf是否使用了GPU
Windows下查看GPU(NVIDIA)使用情况

使用时有错,先把跟包版本有关的列出来:

提示无scipy.misc:
pip install scipy==1.2.1
ModuleNotFoundError: No module named ‘tensorflow.python.types‘

实测可用的解决方案是

pip install tensorflow-estimator==1.15.0

参考链接
如果提示:

tensorflow 1.15.0 requires tensorboard<1.16.0,>=1.15.0, but you have tensorboard 2.0.0 which is incompatible.
tensorflow 1.15.0 requires tensorflow-estimator==1.15.1, but you have tensorflow-estimator 1.15.0 which is incompatible.
应使用
pip install tensorboard==1.15.0

TypeError: batch_normalization() got an unexpected keyword argument ‘decay’

解决方案:

将tf.layers.batch_normalization 替换为 tf.contrib.layers.batch_norm
Process finished with exit code -1073741819 (0xC0000005) --OOM

我的本身环境是TF1.15gpu版,batch_size调成1仍然不行,最后,偶然改动一处,可以跑了.

config.gpu_options.per_process_gpu_memory_fraction = 0.5

在改之前,是0.95
完整显存分配代码

os.environ["CUDA_VISIBLE_DEVICES"] = '0,1'	         # 按照固定的比例分配。
config = tf.ConfigProto(allow_soft_placement=True, log_device_placement=True) 

# 以下代码会占用所有可使用的GPU的50%显存
config.gpu_options.per_process_gpu_memory_fraction = 0.5
config.gpu_options.allow_growth = True

with tf.Session(config=config) as sess:
					...

其他改动可参考:
改绝对路径
改各种期待奇妙事件

OOM : out of memory
为了解决OOM问题,上面博文中的评论,获得了一些包的不坑版本,参考

matplotlib=3.0.2
numpy=1.18 或 1.2.1
h5py==2.9.0

一次迁移实操

目标主机已经安装了pytorch的gpu版本,因此CUDA之类的已经完事了。
这里,可以在pycharm的Terminal进行操作。
操作代码集锦:

conda create -n tf1_gpu python=3.6 tensorflow-gpu=1.15.0

conda activate tf1_gpu

pip install scipy==1.2.1 tensorflow-estimator==1.15.0 tensorboard==1.15.0

python

import tensorflow as tf
tf.test.is_gpu_available()
tf.__version__

如果还有其他包的需求,可参照我的可以运行的环境包版本进行设置:
tf1.15 使用过程中的一些坑_第2张图片

你可能感兴趣的:(笔记,论文,tensorflow1.15,tensorflow)