解决方式1:然而对我这个问题没有效果
def add_summary(self, summary, global_step=None):
"""Adds a `Summary` protocol buffer to the event file.
This method wraps the provided summary in an `Event` protocol buffer
and adds it to the event file.
You can pass the result of evaluating any summary op, using
`tf.Session.run` or
`tf.Tensor.eval`, to this
function. Alternatively, you can pass a `tf.compat.v1.Summary` protocol
buffer that you populate with your own data. The latter is
commonly done to report evaluation results in event files.
Args:
summary: A `Summary` protocol buffer, optionally serialized as a string.
global_step: Number. Optional global step value to record with the
summary.
"""
if isinstance(summary, bytes):
summ = summary_pb2.Summary()
summ.ParseFromString(summary)
summary = summ
# We strip metadata from values with tags that we have seen before in order
# to save space - we just store the metadata on the first value with a
# specific tag.
for value in summary.value:
if not value.metadata:
continue
if value.tag in self._seen_summary_tags:
# This tag has been encountered before. Strip the metadata.
value.ClearField("metadata")
continue
# We encounter a value with a tag we have not encountered previously. And
# it has metadata. Remember to strip metadata from future values with this
# tag string.
self._seen_summary_tags.add(value.tag)
event = event_pb2.Event(summary=summary)
self._add_event(event, global_step)
向事件文件添加一个Summary
协议缓冲区。
此方法将提供的Summary
包装在“事件”协议缓冲区中,并将其添加到事件文件中。
您可以使用tf.Session.run
或tf.Tensor.eval
将评估任何摘要操作的结果传递给此函数。
或者,您可以传递使用自己的数据填充的 tf.compat.v1.Summary
协议缓冲区。后者通常用于在事件文件中报告评估结果。
参数:
Summary
:Summary
协议缓冲区,可选择序列化为字符串。
global_step
:数字。 与Summary
一起记录的可选全局步长值。
解决方式:
没有真正意义上解决,不过确实解决了问题,因为修改前代码对应tensorflow版本低,不知道如何进行修改,添加一个语句就解决了。
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()