需求分析:将使用keras作为torch建模的补充手段,因此需要在服务器(2080ti)上安装tensorflow以及keras.
安装步骤,参考tensorflow官网conda安装说明:
一、官网提供的conda安装代码:
conda install -c anaconda tensorflow
1、执行效果
>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0
>>> print(tf.__version__)
2.0.0
>>> tf.test.is_gpu_available()
2022-04-28 12:43:46.037367: I tensorflow/core/platform/cpu_feature_guard.cc:145]ctions in performance critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriat
2022-04-28 12:43:46.068274: I tensorflow/core/platform/profile_utils/cpu_utils.c
2022-04-28 12:43:46.070731: I tensorflow/compiler/xla/service/service.cc:168] XL
2022-04-28 12:43:46.070800: I tensorflow/compiler/xla/service/service.cc:175]
False
>>> exit()
即这个代码安装的为tensorflow cpu版;如果需要gpu版,原代码需要改为:
conda install -c anaconda tensorflow-gpu
如果还需要keras,建议两者一起安装,即:
conda install -c anaconda tensorflow-gpu keras
2、执行效果
>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0
>>> tf.test.is_gpu_available()
2022-04-28 13:06:10.089525: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2022-04-28 13:06:10.120225: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3199980000 Hz
2022-04-28 13:06:10.122788: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55a799488e90 executing computations on platform Host. Devices:
2022-04-28 13:06:10.122870: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
2022-04-28 13:06:10.125281: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2022-04-28 13:06:10.617368: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:06:10.617686: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: NVIDIA GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.65
pciBusID: 0000:01:00.0
2022-04-28 13:06:10.617816: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2022-04-28 13:06:10.618616: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2022-04-28 13:06:10.619378: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2022-04-28 13:06:10.619564: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0
2022-04-28 13:06:10.620561: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0
2022-04-28 13:06:10.621270: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0
2022-04-28 13:06:10.623569: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2022-04-28 13:06:10.623639: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:06:10.624110: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:06:10.624390: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2022-04-28 13:06:10.624413: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2022-04-28 13:06:10.680460: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-04-28 13:06:10.680485: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0
2022-04-28 13:06:10.680490: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N
2022-04-28 13:06:10.680591: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:06:10.680940: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:06:10.681278: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:06:10.681586: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 10322 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:01:00.0, compute capability: 7.5)
2022-04-28 13:06:10.682761: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55a79a4b2fc0 executing computations on platform CUDA. Devices:
2022-04-28 13:06:10.682774: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): NVIDIA GeForce RTX 2080 Ti, Compute Capability 7.5
True
>>> import keras
Using TensorFlow backend.
>>> exit()
3、应用
$ python cldnn_test.py
2022-04-28 13:17:09.356599: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2022-04-28 13:17:09.838805: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.839436: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: NVIDIA GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.65
pciBusID: 0000:01:00.0
2022-04-28 13:17:09.839614: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2022-04-28 13:17:09.840804: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2022-04-28 13:17:09.841818: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2022-04-28 13:17:09.842058: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0
2022-04-28 13:17:09.843449: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0
2022-04-28 13:17:09.844527: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0
2022-04-28 13:17:09.847919: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2022-04-28 13:17:09.848019: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.848553: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.849011: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2022-04-28 13:17:09.849245: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2022-04-28 13:17:09.855145: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3199980000 Hz
2022-04-28 13:17:09.856057: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5615a1b77c10 executing computations on platform Host. Devices:
2022-04-28 13:17:09.856078: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
2022-04-28 13:17:09.856188: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.856606: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: NVIDIA GeForce RTX 2080 Ti major: 7 minor: 5 memoryClockRate(GHz): 1.65
pciBusID: 0000:01:00.0
2022-04-28 13:17:09.856634: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2022-04-28 13:17:09.856646: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2022-04-28 13:17:09.856657: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2022-04-28 13:17:09.856668: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0
2022-04-28 13:17:09.856680: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0
2022-04-28 13:17:09.856691: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0
2022-04-28 13:17:09.856702: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2022-04-28 13:17:09.856746: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.857147: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.857500: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2022-04-28 13:17:09.857525: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2022-04-28 13:17:09.912196: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-04-28 13:17:09.912220: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0
2022-04-28 13:17:09.912225: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N
2022-04-28 13:17:09.912323: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.912647: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.912950: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-04-28 13:17:09.913234: E tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:47] The TF_FORCE_GPU_ALLOW_GROWTH environment variable is set but could not be parsed: "True". Valid values are "true" or "false". Using original config value of 0.
2022-04-28 13:17:09.913255: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10322 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:01:00.0, compute capability: 7.5)
2022-04-28 13:17:09.914378: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5615a0b84140 executing computations on platform CUDA. Devices:
2022-04-28 13:17:09.914389: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): NVIDIA GeForce RTX 2080 Ti, Compute Capability 7.5
Train on 334672 samples
Epoch 1/250
WARNING:tensorflow:Entity <function Function._initialize_uninitialized_variables.<locals>.initialize_variables at 0x7f0270f7b400> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: No module named 'tensorflow_core.estimator'
2022-04-28 13:17:11.710950: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2022-04-28 13:17:11.835772: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
334672/334672 [==============================] - 57s 171us/sample - loss: 1108.5913
Epoch 2/250