美文网首页
Tensorflow 安装使用和配置

Tensorflow 安装使用和配置

作者: 司书勇 | 来源:发表于2019-08-22 14:34 被阅读0次

    tensorflow 安装使用和配置

    1 tensorflow 安装问题

    • 1 需要先安装CPU版本,再安装GPU版本
    • 2 tensorflow 与keras的版本对应关系
      • 安装命令, python2.7与python3.6命令都是如下所示
      • cudnn版本需要与tensorflow版本保持一致
    tensorflow  1.5 cuda 9.0 
    tensorflow  1.5 和 keras 2.1.4,
                1.4 和 2.1.3 搭配,
                1.3 和 2.1.2 搭配,
                1.2 和 2.1.1 搭配。
    
    conda install tensorflow=1.5
    conda install tensorflow-gpu=1.3   对应的 cudnn:   7.1.3-cuda8.0_0
    conda install keras=2.1.4
    
    • 3 tensorflow 与cudnn版本不一致需要将tensorflow-gpu(cpu 版本保持不变)降级,问题描述如下:
    2019-03-05 10:39:56.790657: E tensorflow/stream_executor/cuda/cuda_dnn.cc:396] Loaded runtime CuDNN library: 7301 (compatibility version 7300) but source was compiled with 7102 (compatibility version 7100).  If using a binary install, upgrade your CuDNN library to match.  If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.
    2019-03-05 10:39:56.791937: F tensorflow/core/kernels/conv_ops.cc:712] Check failed: stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogradNonfusedAlgo<T>(), &algorithms)
    
    • 4 卸载tensorflow-gpu=1.5 安装tensorflow-gpu=1.3,cudnn会自动降级
    conda uninstall tensorflow-gpu
    conda install tensorflow-gpu=1.3
    
    The following NEW packages will be INSTALLED:
    
        backports:           1.0-py36_1           defaults
        backports.weakref:   1.0rc1-py36_0        defaults
        libgcc:              7.2.0-h69d50b8_2     defaults
        tensorflow-gpu:      1.3.0-0              defaults
    
    The following packages will be DOWNGRADED:
    
        cudnn:               7.1.3-cuda8.0_0      defaults --> 6.0.21-cuda8.0_0            defaults
        tensorflow-gpu-base: 1.4.1-py36h01caf0a_0 defaults --> 1.3.0-py36cuda8.0cudnn6.0_1 defaults
    

    2 查看tensorflow是否支持GPU,以及测试程序

    #Python
    import tensorflow as tf
    hello = tf.constant('Hello, TensorFlow!')
    sess = tf.Session()
    print(sess.run(hello))
    
    import tensorflow as tf
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
    
    Device mapping:
    /job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla M40, pci bus id: 0000:03:00.0, compute capability: 5.2
    /job:localhost/replica:0/task:0/device:GPU:1 -> device: 1, name: Tesla M40, pci bus id: 0000:82:00.0, compute capability: 5.2
    2019-03-01 16:11:39.191949: I tensorflow/core/common_runtime/direct_session.cc:297] Device mapping:
    /job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla M40, pci bus id: 0000:03:00.0, compute capability: 5.2
    /job:localhost/replica:0/task:0/device:GPU:1 -> device: 1, name: Tesla M40, pci bus id: 0000:82:00.0, compute capability: 5.2
    

    3 notebook 显存占用不释放

    • notebook 开头加入以下内容
    import os
    import tensorflow as tf 
    
    os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
    os.environ["CUDA_VISIBLE_DEVICES"] = '0'   #指定第一块GPU可用
    config = tf.ConfigProto()
    config.gpu_options.per_process_gpu_memory_fraction = 0.5  # 程序最多只能占用指定gpu50%的显存
    config.gpu_options.allow_growth = True      #程序按需申请内存
    
    

    相关文章

      网友评论

          本文标题:Tensorflow 安装使用和配置

          本文链接:https://www.haomeiwen.com/subject/xzunsctx.html