1、conda create -n tf
?
?
?
(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'
>>>
?错误是因为使用的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
?
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. <==
current version: 4.11.0
latest version: 4.12.0
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: /home/robot/anaconda3/envs/tf
added / updated specs:
- tensorflow-gpu==1.14.0
The following packages will be downloaded:
package | build
---------------------------|-----------------
astor-0.8.1 | py37h06a4308_0 47 KB
gast-0.5.3 | pyhd3eb1b0_0 21 KB
grpcio-1.42.0 | py37hce63b2e_0 2.1 MB
h5py-3.6.0 | py37ha0f2276_0 1.0 MB
importlib-metadata-4.8.2 | py37h06a4308_0 39 KB
keras-applications-1.0.8 | py_1 29 KB
markdown-3.3.4 | py37h06a4308_0 127 KB
mkl-service-2.4.0 | py37h7f8727e_0 56 KB
mkl_fft-1.3.1 | py37hd3c417c_0 172 KB
mkl_random-1.2.2 | py37h51133e4_0 287 KB
numpy-1.21.2 | py37h20f2e39_0 23 KB
numpy-base-1.21.2 | py37h79a1101_0 4.8 MB
protobuf-3.19.1 | py37h295c915_0 306 KB
scipy-1.7.3 | py37hc147768_0 16.4 MB
tensorboard-1.14.0 | py37hf484d3e_0 3.1 MB
tensorflow-1.14.0 |gpu_py37h74c33d7_0 4 KB
tensorflow-base-1.14.0 |gpu_py37he45bfe2_0 146.3 MB
tensorflow-estimator-1.14.0| py_0 261 KB
tensorflow-gpu-1.14.0 | h0d30ee6_0 3 KB
termcolor-1.1.0 | py37h06a4308_1 9 KB
wrapt-1.13.3 | py37h7f8727e_2 51 KB
------------------------------------------------------------
Total: 175.0 MB
The following NEW packages will be INSTALLED:
_tflow_select pkgs/main/linux-64::_tflow_select-2.1.0-gpu
absl-py pkgs/main/noarch::absl-py-0.15.0-pyhd3eb1b0_0
astor pkgs/main/linux-64::astor-0.8.1-py37h06a4308_0
blas pkgs/main/linux-64::blas-1.0-mkl
c-ares pkgs/main/linux-64::c-ares-1.18.1-h7f8727e_0
cached-property pkgs/main/noarch::cached-property-1.5.2-py_0
cudatoolkit pkgs/main/linux-64::cudatoolkit-10.1.243-h6bb024c_0
cudnn pkgs/main/linux-64::cudnn-7.6.5-cuda10.1_0
cupti pkgs/main/linux-64::cupti-10.1.168-0
dataclasses pkgs/main/noarch::dataclasses-0.8-pyh6d0b6a4_7
gast pkgs/main/noarch::gast-0.5.3-pyhd3eb1b0_0
google-pasta pkgs/main/noarch::google-pasta-0.2.0-pyhd3eb1b0_0
grpcio pkgs/main/linux-64::grpcio-1.42.0-py37hce63b2e_0
h5py pkgs/main/linux-64::h5py-3.6.0-py37ha0f2276_0
hdf5 pkgs/main/linux-64::hdf5-1.10.6-hb1b8bf9_0
importlib-metadata pkgs/main/linux-64::importlib-metadata-4.8.2-py37h06a4308_0
intel-openmp pkgs/main/linux-64::intel-openmp-2021.4.0-h06a4308_3561
keras-applications pkgs/main/noarch::keras-applications-1.0.8-py_1
keras-preprocessi~ pkgs/main/noarch::keras-preprocessing-1.1.2-pyhd3eb1b0_0
libgfortran-ng pkgs/main/linux-64::libgfortran-ng-7.5.0-ha8ba4b0_17
libgfortran4 pkgs/main/linux-64::libgfortran4-7.5.0-ha8ba4b0_17
libprotobuf pkgs/main/linux-64::libprotobuf-3.19.1-h4ff587b_0
markdown pkgs/main/linux-64::markdown-3.3.4-py37h06a4308_0
mkl pkgs/main/linux-64::mkl-2021.4.0-h06a4308_640
mkl-service pkgs/main/linux-64::mkl-service-2.4.0-py37h7f8727e_0
mkl_fft pkgs/main/linux-64::mkl_fft-1.3.1-py37hd3c417c_0
mkl_random pkgs/main/linux-64::mkl_random-1.2.2-py37h51133e4_0
numpy pkgs/main/linux-64::numpy-1.21.2-py37h20f2e39_0
numpy-base pkgs/main/linux-64::numpy-base-1.21.2-py37h79a1101_0
protobuf pkgs/main/linux-64::protobuf-3.19.1-py37h295c915_0
scipy pkgs/main/linux-64::scipy-1.7.3-py37hc147768_0
six pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1
tensorboard pkgs/main/linux-64::tensorboard-1.14.0-py37hf484d3e_0
tensorflow pkgs/main/linux-64::tensorflow-1.14.0-gpu_py37h74c33d7_0
tensorflow-base pkgs/main/linux-64::tensorflow-base-1.14.0-gpu_py37he45bfe2_0
tensorflow-estima~ pkgs/main/noarch::tensorflow-estimator-1.14.0-py_0
tensorflow-gpu pkgs/main/linux-64::tensorflow-gpu-1.14.0-h0d30ee6_0
termcolor pkgs/main/linux-64::termcolor-1.1.0-py37h06a4308_1
typing_extensions pkgs/main/noarch::typing_extensions-3.10.0.2-pyh06a4308_0
werkzeug pkgs/main/noarch::werkzeug-2.0.3-pyhd3eb1b0_0
wrapt pkgs/main/linux-64::wrapt-1.13.3-py37h7f8727e_2
zipp pkgs/main/noarch::zipp-3.7.0-pyhd3eb1b0_0
Proceed ([y]/n)?
Downloading and Extracting Packages
h5py-3.6.0 | 1.0 MB | ################################################################################################################### | 100%
grpcio-1.42.0 | 2.1 MB | ################################################################################################################### | 100%
numpy-1.21.2 | 23 KB | ################################################################################################################### | 100%
protobuf-3.19.1 | 306 KB | ################################################################################################################### | 100%
mkl_fft-1.3.1 | 172 KB | ################################################################################################################### | 100%
tensorflow-gpu-1.14. | 3 KB | ################################################################################################################### | 100%
wrapt-1.13.3 | 51 KB | ################################################################################################################### | 100%
tensorboard-1.14.0 | 3.1 MB | ################################################################################################################### | 100%
tensorflow-estimator | 261 KB | ################################################################################################################### | 100%
keras-applications-1 | 29 KB | ################################################################################################################### | 100%
numpy-base-1.21.2 | 4.8 MB | ################################################################################################################### | 100%
gast-0.5.3 | 21 KB | ################################################################################################################### | 100%
astor-0.8.1 | 47 KB | ################################################################################################################### | 100%
tensorflow-base-1.14 | 146.3 MB | ################################################################################################################### | 100%
mkl_random-1.2.2 | 287 KB | ################################################################################################################### | 100%
tensorflow-1.14.0 | 4 KB | ################################################################################################################### | 100%
mkl-service-2.4.0 | 56 KB | ################################################################################################################### | 100%
importlib-metadata-4 | 39 KB | ################################################################################################################### | 100%
scipy-1.7.3 | 16.4 MB | ################################################################################################################### | 100%
termcolor-1.1.0 | 9 KB | ################################################################################################################### | 100%
markdown-3.3.4 | 127 KB | ################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
?测试:
(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
(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'
|