我在Anaconda环境中的Windows 10 Pro上安装了Tensorflow。当我尝试使用tf.summary API时,我系统地得到AttributeError:
python --version
Python 3.8.12
python
>>> import tensorflow as tf
2022-03-30 09:09:03.938282: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-03-30 09:09:03.939342: 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.
C:UsersJohnDoeAnaconda3envstfenvlibsite-packagesnumpy_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:
C:UsersJohnDoeAnaconda3envstfenvlibsite-packagesnumpy.libslibopenblas.EL2C6PLE4ZYW3ECEVIV3OXXGRN2NRFM2.gfortran-win_amd64.dll
C:UsersJohnDoeAnaconda3envstfenvlibsite-packagesnumpy.libslibopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
warnings.warn("loaded more than 1 DLL from .libs:"
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
>>> print(tf.__version__)
2.8.0
>>> dir(tf.summary)
['SummaryWriter', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_sys', 'create_file_writer', 'create_noop_writer', 'experimental', 'flush', 'graph', 'record_if', 'should_record_summaries', 'trace_export', 'trace_off', 'trace_on', 'write']
>>> tf.summary.image()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow._api.v2.summary' has no attribute 'image'
>>> tf.summary.scalar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow._api.v2.summary' has no attribute 'scalar'
根据文档,image和scalar是TF2.8中tf.summary的属性。此错误是否与Windows有关?我使用Anaconda来管理我的环境,但TF是用PIP安装的。
我通过强制重新安装tensorboard解决了这个问题:
pip install --force --no-deps tensorboard
在那之后,一切都很顺利。