Tensorflow 安装使用和配置

2019-08-22  本文已影响0人  司书勇

tensorflow 安装使用和配置

1 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
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)
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 显存占用不释放

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      #程序按需申请内存

上一篇 下一篇

猜你喜欢

热点阅读