from tensorboardX import SummaryWriter 仅在第二次工作

from tensorboardX import SummaryWriter only works the second time

在 ipython 如果我这样做:

from tensorboardX import SummaryWriter

我收到一长串错误(如下所示)。

但如果我再做一次,我就不会出错。这是为什么?

错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-447df71b09db> in <module>
----> 1 from tensorboardX import SummaryWriter

~/.local/lib/python3.8/site-packages/tensorboardX/__init__.py in <module>
      2 """
      3 
----> 4 from .writer import FileWriter, SummaryWriter
      5 from .record_writer import RecordWriter

~/.local/lib/python3.8/site-packages/tensorboardX/writer.py in <module>
     22 import json
     23 import os
---> 24 from .src import event_pb2
     25 from .src import summary_pb2
     26 from .src import graph_pb2

~/.local/lib/python3.8/site-packages/tensorboardX/src/event_pb2.py in <module>
     14 
     15 
---> 16 from tensorboard.src import summary_pb2 as tensorboard_dot_src_dot_summary__pb2
     17 
     18 

~/.local/lib/python3.8/site-packages/tensorboard/__init__.py in <module>
      2 """
      3 
----> 4 from .writer import FileWriter, SummaryWriter
      5 from .record_writer import RecordWriter

~/.local/lib/python3.8/site-packages/tensorboard/writer.py in <module>
     26 from .src import graph_pb2
     27 from .event_file_writer import EventFileWriter
---> 28 from .summary import scalar, histogram, image, audio, text
     29 from .graph import graph
     30 from .embedding import make_mat, make_sprite, make_tsv, append_pbtxt

~/.local/lib/python3.8/site-packages/tensorboard/summary/__init__.py in <module>
     20 # If the V1 summary API is accessible, load and re-export it here.
     21 try:
---> 22     from tensorboard.summary import v1  # noqa: F401
     23 except ImportError:
     24     pass

~/.local/lib/python3.8/site-packages/tensorboard/summary/v1.py in <module>
     19 """
     20 
---> 21 from tensorboard.plugins.audio import summary as _audio_summary
     22 from tensorboard.plugins.custom_scalar import summary as _custom_scalar_summary
     23 from tensorboard.plugins.histogram import summary as _histogram_summary

~/.local/lib/python3.8/site-packages/tensorboard/plugins/audio/summary.py in <module>
     32 
     33 from tensorboard.util import encoder as encoder_util
---> 34 from tensorboard.plugins.audio import metadata
     35 from tensorboard.plugins.audio import summary_v2
     36 

~/.local/lib/python3.8/site-packages/tensorboard/plugins/audio/metadata.py in <module>
     16 
     17 
---> 18 from tensorboard.compat.proto import summary_pb2
     19 from tensorboard.plugins.audio import plugin_data_pb2
     20 

~/.local/lib/python3.8/site-packages/tensorboard/compat/proto/summary_pb2.py in <module>
     15 
     16 
---> 17 from tensorboard.compat.proto import tensor_pb2 as tensorboard_dot_compat_dot_proto_dot_tensor__pb2
     18 
     19 

~/.local/lib/python3.8/site-packages/tensorboard/compat/proto/tensor_pb2.py in <module>
     14 
     15 
---> 16 from tensorboard.compat.proto import resource_handle_pb2 as tensorboard_dot_compat_dot_proto_dot_resource__handle__pb2
     17 from tensorboard.compat.proto import tensor_shape_pb2 as tensorboard_dot_compat_dot_proto_dot_tensor__shape__pb2
     18 from tensorboard.compat.proto import types_pb2 as tensorboard_dot_compat_dot_proto_dot_types__pb2

~/.local/lib/python3.8/site-packages/tensorboard/compat/proto/resource_handle_pb2.py in <module>
     14 
     15 
---> 16 from tensorboard.compat.proto import tensor_shape_pb2 as tensorboard_dot_compat_dot_proto_dot_tensor__shape__pb2
     17 from tensorboard.compat.proto import types_pb2 as tensorboard_dot_compat_dot_proto_dot_types__pb2
     18 

~/.local/lib/python3.8/site-packages/tensorboard/compat/proto/tensor_shape_pb2.py in <module>
     16 
     17 
---> 18 DESCRIPTOR = _descriptor.FileDescriptor(
     19   name='tensorboard/compat/proto/tensor_shape.proto',
     20   package='tensorboard',

~/.local/lib/python3.8/site-packages/google/protobuf/descriptor.py in __new__(cls, name, package, options, serialized_options, serialized_pb, dependencies, public_dependencies, syntax, pool, create_key)
    981           raise RuntimeError('Please link in cpp generated lib for %s' % (name))
    982       elif serialized_pb:
--> 983         return _message.default_pool.AddSerializedFile(serialized_pb)
    984       else:
    985         return super(FileDescriptor, cls).__new__(cls)

TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "tensorboard/compat/proto/tensor_shape.proto":
  tensorboard.TensorShapeProto.dim: "tensorboard.TensorShapeProto.dim" is already defined in file "tensorboard/src/tensor_shape.proto".
  tensorboard.TensorShapeProto.unknown_rank: "tensorboard.TensorShapeProto.unknown_rank" is already defined in file "tensorboard/src/tensor_shape.proto".
  tensorboard.TensorShapeProto.Dim.size: "tensorboard.TensorShapeProto.Dim.size" is already defined in file "tensorboard/src/tensor_shape.proto".
  tensorboard.TensorShapeProto.Dim.name: "tensorboard.TensorShapeProto.Dim.name" is already defined in file "tensorboard/src/tensor_shape.proto".
  tensorboard.TensorShapeProto.Dim: "tensorboard.TensorShapeProto.Dim" is already defined in file "tensorboard/src/tensor_shape.proto".
  tensorboard.TensorShapeProto: "tensorboard.TensorShapeProto" is already defined in file "tensorboard/src/tensor_shape.proto".
  tensorboard.TensorShapeProto.dim: "tensorboard.TensorShapeProto.Dim" seems to be defined in "tensorboard/src/tensor_shape.proto", which is not imported by "tensorboard/compat/proto/tensor_shape.proto".  To use it here, please add the necessary import.

看看升级模块是否有帮助..

pip install --upgrade tensorboardX

因为这个库在我这边是没有问题的,所以试试这个

try:from tensorboardX import SummaryWriter
except:from tensorboardX import SummaryWriter

希望对您有所帮助。通过搜索“Couldn't build proto file into descriptor pool”

得到

pip uninstall protobuf
pip install --no-binary=protobuf protobuf

有关解释和更多信息,请参阅

https://github.com/ValvePython/csgo/issues/8#issuecomment-296345877