TypeError:__init __()获得了意外的关键字参数'log_dir'

时间:2019-06-19 09:57:45

标签: python python-3.x

def _get_file_writer(self):
        """Returns the default FileWriter instance. Recreates it if closed."""
        if not self._write_to_disk:
            self.file_writer = DummyFileWriter(logdir=self.logdir)
            self.all_writers = {self.file_writer.get_logdir(): self.file_writer}
            return self.file_writer

        if self.all_writers is None or self.file_writer is None:
            if 'purge_step' in self.kwargs.keys():
                most_recent_step = self.kwargs.pop('purge_step')
                self.file_writer = FileWriter(logdir=self.logdir, **self.kwargs)
                self.file_writer.add_event(
                    Event(step=most_recent_step, file_version='brain.Event:2'))
                self.file_writer.add_event(
                    Event(step=most_recent_step, session_log=SessionLog(status=SessionLog.START)))
            else:
                self.file_writer = FileWriter(logdir=self.logdir, **self.kwargs)
            self.all_writers = {self.file_writer.get_logdir(): self.file_writer}
        return self.file_writer

    def add_scalar(self, tag, scalar_value, global_step=None, walltime=None):
        """Add scalar data to summary.
  File "C:\Users\dell\Anaconda3\envs\tensorenviron\lib\site-packages\tensorboardX\writer.py", line 310, in _get_file_writer
    self.file_writer = FileWriter(logdir=self.logdir, **self.kwargs)
TypeError: __init__() got an unexpected keyword argument 'log_dir'

1 个答案:

答案 0 :(得分:0)

问题不在此代码段之内,可能是初始化任何类_get_file_writer的一部分。您的字典self.kwargs包含一个log_dir密钥,您将通过**self.kwargs将该密钥传递给FileWriter,而tf.summary.FileWriter则期望logdir