WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.如何解决?

本文详细解析了TensorFlow中关于summary API的警告,指出由于TensorBoard缺失导致的问题。提供了解决方案,包括检查安装、重新安装匹配版本的TensorBoard,确保模型训练顺利进行。
摘要由CSDN通过智能技术生成

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.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.

如果这个不解决,以后调用 tensorflow.keras.applications. 下面的模型,训练时会报错

AttributeError: module 'tensorflow.compat.v2.summary' has no attribute 'scalar'

比如

import tensorflow as tf
mobile_net = tf.keras.applications.MobileNetV2(input_shape=(128, 128, 3), include_top=False)

model = tf.keras.Sequential([mobile_net,
                            tf.keras.layers.GlobalAveragePooling2D(),
                            tf.keras.layers.Dense(10)])
model.summary()

model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
             loss = 'sparse_categorical_crossentropy',
             metrics=['accuracy'])
history = model.fit(dataset, epochs=30,validation_data=test_dataset)

就会出现错误提示

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_14420/981598541.py in <module>
----> 1 history = model.fit(dataset, epochs=30, steps_per_epoch=20,validation_data=test_dataset)

~\AppData\Roaming\Python\Python38\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

~\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\func_graph.py in autograph_handler(*args, **kwargs)
   1127           except Exception as e:  # pylint:disable=broad-except
   1128             if hasattr(e, "ag_error_metadata"):
-> 1129               raise e.ag_error_metadata.to_exception(e)
   1130             else:
   1131               raise

AttributeError: in user code:

    File "C:\Users\52255\AppData\Roaming\Python\Python38\site-packages\keras\engine\training.py", line 878, in train_function  *
        return step_function(self, iterator)
    File "C:\Users\52255\AppData\Roaming\Python\Python38\site-packages\keras\engine\training.py", line 870, in step_function  **
        write_scalar_summaries(outputs, step=model._train_counter)  # pylint: disable=protected-access
    File "C:\Users\52255\AppData\Roaming\Python\Python38\site-packages\keras\engine\training.py", line 3051, in write_scalar_summaries
        tf.summary.scalar('batch_' + name, value, step=step)
AttributeError: module 'tensorflow.compat.v2.summary' has no attribute 'scalar'

上面图和代码是我后面截屏的,可能对不上,但是错误肯定一样。

原因分析并解决

tensorboard没有安装或者版本与tensorflow版本不兼容

  • 用pip list查看
pip list 
  • 没有安装直接安装就好了
pip install tensorboard -i https://pypi.tuna.tsinghua.edu.cn/simple
  • 如果已经安装,卸载并安装和tensorflow一样的版本
  • 比如 我用的tensorflow 2.7版本,则安装2.7版本的tensorboard
pip uninstall tensorboard
pip install tensorboard==2.7 -i https://pypi.tuna.tsinghua.edu.cn/simple

End

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值