Tensorflow (0) 安装

1、conda create -n tf

Tensorflow (0) 安装

Tensorflow (0) 安装

Tensorflow (0) 安装

Tensorflow (0) 安装

Tensorflow (0) 安装

Tensorflow (0) 安装
(tf) robot@robot-All-Series:~$ python
Python 3.9.7 (default, Sep 16 2021, 13:09:58)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf
2022-03-22 10:48:03.479799: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
>>> hello = tf.constant('Hellllo')
2022-03-22 10:48:37.685215: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2022-03-22 10:48:37.686987: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2022-03-22 10:48:37.741005: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:05:00.0 name: NVIDIA TITAN Xp computeCapability: 6.1
coreClock: 1.582GHz coreCount: 30 deviceMemorySize: 11.91GiB deviceMemoryBandwidth: 510.07GiB/s
2022-03-22 10:48:37.741362: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 1 with properties:
pciBusID: 0000:09:00.0 name: NVIDIA TITAN Xp computeCapability: 6.1
coreClock: 1.582GHz coreCount: 30 deviceMemorySize: 11.91GiB deviceMemoryBandwidth: 510.07GiB/s
2022-03-22 10:48:37.741391: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2022-03-22 10:48:37.743109: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10
2022-03-22 10:48:37.743152: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10
2022-03-22 10:48:37.744683: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2022-03-22 10:48:37.744945: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2022-03-22 10:48:37.746622: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2022-03-22 10:48:37.747540: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10
2022-03-22 10:48:37.751180: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7
2022-03-22 10:48:37.752242: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0, 1
2022-03-22 10:48:37.752584: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

2022-03-22 10:48:38.084989: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:05:00.0 name: NVIDIA TITAN Xp computeCapability: 6.1
coreClock: 1.582GHz coreCount: 30 deviceMemorySize: 11.91GiB deviceMemoryBandwidth: 510.07GiB/s
2022-03-22 10:48:38.085183: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 1 with properties:
pciBusID: 0000:09:00.0 name: NVIDIA TITAN Xp computeCapability: 6.1
coreClock: 1.582GHz coreCount: 30 deviceMemorySize: 11.91GiB deviceMemoryBandwidth: 510.07GiB/s
2022-03-22 10:48:38.085208: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2022-03-22 10:48:38.085249: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10
2022-03-22 10:48:38.085265: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10
2022-03-22 10:48:38.085279: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2022-03-22 10:48:38.085297: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2022-03-22 10:48:38.085313: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2022-03-22 10:48:38.085331: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10
2022-03-22 10:48:38.085347: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7
2022-03-22 10:48:38.085933: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0, 1
2022-03-22 10:48:38.085967: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2022-03-22 10:48:38.747587: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-03-22 10:48:38.747628: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267]      0 1
2022-03-22 10:48:38.747640: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0:   N Y
2022-03-22 10:48:38.747647: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 1:   Y N
2022-03-22 10:48:38.748426: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10902 MB memory) -> physical GPU (device: 0, name: NVIDIA TITAN Xp, pci bus id: 0000:05:00.0, compute capability: 6.1)
2022-03-22 10:48:38.748996: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 11208 MB memory) -> physical GPU (device: 1, name: NVIDIA TITAN Xp, pci bus id: 0000:09:00.0, compute capability: 6.1)
2022-03-22 10:48:38.749209: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
>>> se=tf.Session
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'Session'
>>> se=tf.Session()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'Session'
>>> se1 = tf.Session()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'Session'
>>> tf.__version__
'2.4.1'
>>>
</module></stdin></module></stdin></module></stdin>

错误是因为使用的tensorflow 2.0以上版本。

更换为1.14.0

conda uninstall tensorflow-gpu

conda install tensorflow-gpu==1.14.0

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - tensorflow-gpu==1.14.0 -> python[version='2.7.*|3.6.*|3.7.*']

Your python: python=3.9

If python is on the left-most side of the chain, that's the version you've asked for.

When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with your system:

  - feature:/linux-64::__glibc==2.31=0
  - feature:|@/linux-64::__glibc==2.31=0

Your installed version is: 2.31

更改python版本为3.7.11

Tensorflow (0) 安装
Downloading and Extracting Packages
certifi-2021.10.8    | 151 KB    | ################################################################################################################### | 100%
python-3.7.11        | 45.3 MB   | ################################################################################################################### | 100%
pip-21.2.2           | 1.8 MB    | ################################################################################################################### | 100%
setuptools-58.0.4    | 775 KB    | ################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(tf) robot@robot-All-Series:~$ conda install tensorflow-gpu==1.14.0
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

Collecting package metadata (repodata.json): done
Solving environment: done

==> WARNING: A newer version of conda exists. <== 3 4 9 21 23 29 39 47 51 56 127 172 261 287 306 current version: 4.11.0 latest 4.12.0 please update conda by running $ -n base -c defaults ## package plan environment location: home robot anaconda3 envs tf added updated specs: - tensorflow-gpu="=1.14.0" the following packages will be downloaded: | build ---------------------------|----------------- astor-0.8.1 py37h06a4308_0 kb gast-0.5.3 pyhd3eb1b0_0 grpcio-1.42.0 py37hce63b2e_0 2.1 mb h5py-3.6.0 py37ha0f2276_0 1.0 importlib-metadata-4.8.2 keras-applications-1.0.8 py_1 markdown-3.3.4 mkl-service-2.4.0 py37h7f8727e_0 mkl_fft-1.3.1 py37hd3c417c_0 mkl_random-1.2.2 py37h51133e4_0 numpy-1.21.2 py37h20f2e39_0 numpy-base-1.21.2 py37h79a1101_0 4.8 protobuf-3.19.1 py37h295c915_0 scipy-1.7.3 py37hc147768_0 16.4 tensorboard-1.14.0 py37hf484d3e_0 3.1 tensorflow-1.14.0 |gpu_py37h74c33d7_0 tensorflow-base-1.14.0 |gpu_py37he45bfe2_0 146.3 tensorflow-estimator-1.14.0| py_0 tensorflow-gpu-1.14.0 h0d30ee6_0 termcolor-1.1.0 py37h06a4308_1 wrapt-1.13.3 py37h7f8727e_2 ------------------------------------------------------------ total: 175.0 new installed: _tflow_select pkgs main linux-64::_tflow_select-2.1.0-gpu absl-py noarch::absl-py-0.15.0-pyhd3eb1b0_0 astor linux-64::astor-0.8.1-py37h06a4308_0 blas linux-64::blas-1.0-mkl c-ares linux-64::c-ares-1.18.1-h7f8727e_0 cached-property noarch::cached-property-1.5.2-py_0 cudatoolkit linux-64::cudatoolkit-10.1.243-h6bb024c_0 cudnn linux-64::cudnn-7.6.5-cuda10.1_0 cupti linux-64::cupti-10.1.168-0 dataclasses noarch::dataclasses-0.8-pyh6d0b6a4_7 gast noarch::gast-0.5.3-pyhd3eb1b0_0 google-pasta noarch::google-pasta-0.2.0-pyhd3eb1b0_0 grpcio linux-64::grpcio-1.42.0-py37hce63b2e_0 h5py linux-64::h5py-3.6.0-py37ha0f2276_0 hdf5 linux-64::hdf5-1.10.6-hb1b8bf9_0 importlib-metadata linux-64::importlib-metadata-4.8.2-py37h06a4308_0 intel-openmp linux-64::intel-openmp-2021.4.0-h06a4308_3561 keras-applications noarch::keras-applications-1.0.8-py_1 keras-preprocessi~ noarch::keras-preprocessing-1.1.2-pyhd3eb1b0_0 libgfortran-ng linux-64::libgfortran-ng-7.5.0-ha8ba4b0_17 libgfortran4 linux-64::libgfortran4-7.5.0-ha8ba4b0_17 libprotobuf linux-64::libprotobuf-3.19.1-h4ff587b_0 markdown linux-64::markdown-3.3.4-py37h06a4308_0 mkl linux-64::mkl-2021.4.0-h06a4308_640 mkl-service linux-64::mkl-service-2.4.0-py37h7f8727e_0 mkl_fft linux-64::mkl_fft-1.3.1-py37hd3c417c_0 mkl_random linux-64::mkl_random-1.2.2-py37h51133e4_0 numpy linux-64::numpy-1.21.2-py37h20f2e39_0 numpy-base linux-64::numpy-base-1.21.2-py37h79a1101_0 protobuf linux-64::protobuf-3.19.1-py37h295c915_0 scipy linux-64::scipy-1.7.3-py37hc147768_0 six noarch::six-1.16.0-pyhd3eb1b0_1 tensorboard linux-64::tensorboard-1.14.0-py37hf484d3e_0 tensorflow linux-64::tensorflow-1.14.0-gpu_py37h74c33d7_0 tensorflow-base linux-64::tensorflow-base-1.14.0-gpu_py37he45bfe2_0 tensorflow-estima~ noarch::tensorflow-estimator-1.14.0-py_0 linux-64::tensorflow-gpu-1.14.0-h0d30ee6_0 termcolor linux-64::termcolor-1.1.0-py37h06a4308_1 typing_extensions noarch::typing_extensions-3.10.0.2-pyh06a4308_0 werkzeug noarch::werkzeug-2.0.3-pyhd3eb1b0_0 wrapt linux-64::wrapt-1.13.3-py37h7f8727e_2 zipp noarch::zipp-3.7.0-pyhd3eb1b0_0 proceed ([y] n)? downloading and extracting ################################################################################################################### 100% tensorflow-gpu-1.14. tensorflow-estimator keras-applications-1 tensorflow-base-1.14 importlib-metadata-4 preparing transaction: done verifying executing done< code></==>

测试:

(tf) robot@robot-All-Series:~$ python
Python 3.7.11 (default, Jul 27 2021, 14:32:16)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf
/home/robot/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

  _np_qint8 = np.dtype([("qint8", np.int8, 1)])

tensorflow版本与numpy版本不匹配。

运行tensorflow代码出现dtypes.py:516: FutureWarning: Passing (type, 1) or ‘1type的解决方法_TanH.blog的博客-CSDN博客

pip uninstall numpy (conda uninstall numpy 失败)

再安装低版本的numpy:

conda install numpy==1.16.0

Tensorflow (0) 安装

再测试tensorflow

(tf) robot@robot-All-Series:~$ python
Python 3.7.11 (default, Jul 27 2021, 14:32:16)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf
>>> hello = tf.constant('Hellllo')
>>> se = tf.Session()
2022-03-22 14:51:18.028177: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
2022-03-22 14:51:18.076529: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: NVIDIA TITAN Xp major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:05:00.0
2022-03-22 14:51:18.076872: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 1 with properties:
name: NVIDIA TITAN Xp major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:09:00.0
2022-03-22 14:51:18.077112: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
2022-03-22 14:51:18.078664: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10
2022-03-22 14:51:18.080182: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10
2022-03-22 14:51:18.080425: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10
2022-03-22 14:51:18.082062: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10
2022-03-22 14:51:18.082934: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10
2022-03-22 14:51:18.086484: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
2022-03-22 14:51:18.087523: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0, 1
2022-03-22 14:51:18.087881: 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-03-22 14:51:18.093333: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3598195000 Hz
2022-03-22 14:51:18.093815: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5648ea47a380 executing computations on platform Host. Devices:
2022-03-22 14:51:18.093837: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2022-03-22 14:51:18.409987: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: NVIDIA TITAN Xp major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:05:00.0
2022-03-22 14:51:18.410173: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 1 with properties:
name: NVIDIA TITAN Xp major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:09:00.0
2022-03-22 14:51:18.410209: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
2022-03-22 14:51:18.410224: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10
2022-03-22 14:51:18.410237: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10
2022-03-22 14:51:18.410249: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10
2022-03-22 14:51:18.410262: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10
2022-03-22 14:51:18.410273: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10
2022-03-22 14:51:18.410286: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
2022-03-22 14:51:18.410886: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0, 1
2022-03-22 14:51:18.410923: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.1
2022-03-22 14:51:18.411292: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-03-22 14:51:18.411309: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 1
2022-03-22 14:51:18.411316: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N Y
2022-03-22 14:51:18.411322: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 1:   Y N
2022-03-22 14:51:18.411985: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 11158 MB memory) -> physical GPU (device: 0, name: NVIDIA TITAN Xp, pci bus id: 0000:05:00.0, compute capability: 6.1)
2022-03-22 14:51:18.412570: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 11435 MB memory) -> physical GPU (device: 1, name: NVIDIA TITAN Xp, pci bus id: 0000:09:00.0, compute capability: 6.1)
2022-03-22 14:51:18.414187: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5648ecb68fa0 executing computations on platform CUDA. Devices:
2022-03-22 14:51:18.414207: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): NVIDIA TITAN Xp, Compute Capability 6.1
2022-03-22 14:51:18.414216: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (1): NVIDIA TITAN Xp, Compute Capability 6.1
>>> print(se.run(hello))
b'Hellllo'
</undefined></undefined>

Original: https://blog.csdn.net/light169/article/details/123654462
Author: light169
Title: Tensorflow (0) 安装

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/521198/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球