新手小白打开tensorboard 面板 tensorflow2.0版本ValueError: Not a TBLoader or TBPlugin subclass:等问题

源代码:

import tensorflow as tf
import datetime

mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

def create_model():
  return tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(512, activation='relu'),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation='softmax')
  ])
model = create_model()
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

#log_dir="logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") 
log_dir = "E:\logs"
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)

model.fit(x=x_train, 
          y=y_train, 
          epochs=5, 
          validation_data=(x_test, y_test), 
          callbacks=[tensorboard_callback])

代码是TF官网上直接copy过来的,运行在windows环境上路径除了一点问题,我直接注释掉了,然后加了自己要存放的路径,我放在E盘的logs文件夹下。
运行就Ok了。
新手小白打开tensorboard 面板 tensorflow2.0版本ValueError: Not a TBLoader or TBPlugin subclass:等问题_第1张图片

接下来是打开tensorboard的步骤。
首先按照网上的教程进入保存log的目录文件夹,并且输入,命令打开tensorflow出错:
新手小白打开tensorboard 面板 tensorflow2.0版本ValueError: Not a TBLoader or TBPlugin subclass:等问题_第2张图片

一开始以为是tensorboard.exe的路径没有加到系统的Path环境变量里面,出现这一问题的朋友可以找一找相关教程。
加了之后依旧出现这样的错误。

发现在python环境中运行tensorboard命令,出现错误:

>>> tensorboard --logdir==E:\logs
  File "", line 1
    tensorboard --logdir==E:\logs
                                ^
SyntaxError: unexpected character after line continuation character

使用退出命令退出后这个问题被解决:

>>> exit()

再启动相关命令:

E:\logs>tensorboard --dirlog==E:\logs

出错:

Traceback (most recent call last):
  File "e:\download\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "e:\download\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\Download\Scripts\tensorboard.exe\__main__.py", line 9, in <module>
  File "e:\download\lib\site-packages\tensorboard\main.py", line 59, in run_main
    program.get_default_assets_zip_provider())
  File "e:\download\lib\site-packages\tensorboard\program.py", line 144, in __init__
    self.plugin_loaders = [make_loader(p) for p in plugins]
  File "e:\download\lib\site-packages\tensorboard\program.py", line 144, in <listcomp>
    self.plugin_loaders = [make_loader(p) for p in plugins]
  File "e:\download\lib\site-packages\tensorboard\program.py", line 143, in make_loader
    raise ValueError("Not a TBLoader or TBPlugin subclass: %s" % plugin)
ValueError: Not a TBLoader or TBPlugin subclass: <class 'tensorboard_plugin_wit.wit_plugin_loader.WhatIfToolPluginLoader'>

奇奇怪怪的错误啊,小白心累啊。根据一些博主的回答,使用conda list 命令看已经安装的包:
新手小白打开tensorboard 面板 tensorflow2.0版本ValueError: Not a TBLoader or TBPlugin subclass:等问题_第3张图片
发现,tensorboard和tensorflow的版本不一样。
可能因为版本的问题,没有一致版本的:
我先用 命令卸载了tensorboard的两个包:

E:\logs>pip uninstall tensorboard
Uninstalling tensorboard-2.3.0:
  Would remove:
    e:\download\lib\site-packages\tensorboard-2.3.0.dist-info\*
    e:\download\lib\site-packages\tensorboard\*
    e:\download\scripts\tensorboard.exe
  Would not remove (might be manually added):
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\filters\_base.py
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\ihatexml.py
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\inputstream.py
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\sanitizer.py
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\serializer\__init__.py
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\serializer\htmlserializer.py
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\tokenizer.py
    e:\download\lib\site-packages\tensorboard\_vendor\html5lib\treebuilders\_base.py
    ...
E:\logs>pip install tensorboard-2.0.0b1
Collecting tensorboard-2.0.0b1
  ERROR: Could not find a version that satisfies the requirement tensorboard-2.0.0b1 (from versions: none)
ERROR: No matching distribution found for tensorboard-2.0.0b1
E:\logs>pip install tensorboard-2.0.0
Collecting tensorboard-2.0.0
ERROR: Could not find a version that satisfies the requirement tensorboard-2.0.0 (from versions: none)
ERROR: No matching distribution found for tensorboard-2.0.0

没有2.0的版本啊!!算了,还是安装原来的版本叭

E:\logs>pip install tensorboard
Collecting tensorboard
  Using cached https://files.pythonhosted.org/packages/e9/1b/6a420d7e6ba431cf3d51b2a5bfa06a958c4141e3189385963dc7f6fbffb6/tensorboard-2.3.0-py3-none-any.whl
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in e:\download\lib\site-packages (from tensorboard) (1.7.0)
Requirement already satisfied: protobuf>=3.6.0 in e:\download\lib\site-packages (from tensorboard) (3.13.0)
Requirement already satisfied: requests<3,>=2.21.0 in e:\download\lib\site-packages (from tensorboard) (2.22.0)
Requirement already satisfied: google-auth<2,>=1.6.3 in e:\download\lib\site-packages (from tensorboard) (1.22.1)
...

对另一个包也使用相同的方法,卸了再装一遍,发现问题解决了! ???


E:\logs>tensorboard --logdir=E:\logs
Serving TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all
TensorBoard 2.3.0 at http://localhost:6006/ (Press CTRL+C to quit)

将url输入到浏览器,ok了。

新手小白打开tensorboard 面板 tensorflow2.0版本ValueError: Not a TBLoader or TBPlugin subclass:等问题_第4张图片

总结一下:
(1) 注意添加tensorboard.exe文件路径到系统环境变量里。
(2)可以直接在cmd中输入tensorboard命令,无需进入到python环境中导入tensorflow包。
(3)遇到最后一种错误,可以尝试将原来的包卸载了再装一遍,可能会解决问题。

最后,虽然小白还是迷迷糊糊的,但很开心问题被解决掉了。
希望看到的大神,可以评论交流一下呀!

你可能感兴趣的:(BUG记录,tensorflow,python,anaconda,cmd)