pytorch出现问题,v1.summary.FileWriter is not compatible with eager execution

出错信息如下

img
代码为

img
什么原因呢?
我本来以为时tensorflow版本过高,之前的tensorflow是2.6的,现在改到了1.12,还是错。
需要说明一下,我这个网络是既有tensorflow又有pytorch,我是在pytorch环境下装的tensorflow,没办法,因为这个网络的READEME.md说需要这俩。
有没有真正懂得,帮忙解决一下,不胜感激!

FileWriter类提供的是在给定目录中创建事件文件,并向这个文件添加摘要和事件的机制。当启用了eager execution的时候FileWriter就会报这个错。
我看不到你的Logger类具体的写了什么,你尝试一下把你Logger中的代码改成这种形式就不会报这个错了。

from tensorflow.python.summary.writer import writer
import tensorflow as tf

with tf.compat.v1.Graph().as_default():
  a = writer.FileWriter('test')

补充:
你把Logger的init函数修改为如下。


def init(self, log_dir):
    """Create a summary writer logging to log_dir."""
    # self.writer = tf.compat.v1.summary.FileWriter(log_dir)

    from tensorflow.python.summary.writer import writer
    import tensorflow as tf

    with tf.compat.v1.Graph().as_default():
        self.writer = writer.FileWriter(log_dir)

你注意识别一下import的包不同版本有差异。