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