安装TF2.4
使用指定版本方法安装
pip3 install tensorflow==2.4.0
安装成功
安装后进行测试
import tensorflow as tf
# import os
#
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
hello = tf.constant("hello tensorflow")
print(hello)
程序可以运行,但出现如下错误
D:\python3venv\tf24\Scripts\python.exe D:/pyspace/venvdemo/test.py
2021-07-15 16:38:49.181471: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-07-15 16:38:49.181647: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
tf.Tensor(b'hello tensorflow', shape=(), dtype=string)
2021-07-15 16:38:51.423703: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-07-15 16:38:51.425819: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2021-07-15 16:38:51.425991: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303)
2021-07-15 16:38:51.432105: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-LVFJD7Q
2021-07-15 16:38:51.432421: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-LVFJD7Q
2021-07-15 16:38:51.432780: 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: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-07-15 16:38:51.433334: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
加上CPU
使用指定CPU和版本方法安装
pip3 install tensorflow-cpu==2.4.0
也能安装成功
安装后进行测试
import tensorflow as tf
# import os
#
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
hello = tf.constant("hello tensorflow")
print(hello)
程序可以运行,错误也减少了,但还是出现如下错误
D:\python3venv\tf24cpu\Scripts\python.exe D:/pyspace/venvdemocpu/test.py
tf.Tensor(b'hello tensorflow', shape=(), dtype=string)
2021-07-15 17:01:21.581728: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-07-15 17:01:21.582370: 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: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
这两条应该是警告信息
在放开日志等级之后再次运行,两条信息就不显示了。
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
hello = tf.constant("hello tensorflow")
print(hello)
D:\python3venv\tf24cpu\Scripts\python.exe D:/pyspace/venvdemocpu/test.py
tf.Tensor(b'hello tensorflow', shape=(), dtype=string)
Process finished with exit code 0
结论(个人理解)
对于安装TensorFlow2.X版本来说,如果没有GPU
安装时应该使用pip install tensorflow-cpu
如果使用pip install tensorflow
,也可以使用,但是会有警告信息,并且这个信息调整日志等级不起作用