TensorFlow技术帖

keras调用tensorborad时报错 AttributeE

2020-02-22  本文已影响0人  洗洗睡吧i

keras调用tensorborad时报错:
AttributeError: 'Model' object has no attribute '_get_distribution_strategy'

软件版本:

解决办法A:

The changes introduced in 06d8f77 are not compatible with standalone Keras (they are compatible with tf.Keras). a keras.Model does not have a _get_distribution_strategy method, which is now assumed for the Tensorboard callback.

相关代码如下。

# 1529行左右 : # distributed_file_utils.write_dirpath()

    # In case this callback is used via native Keras, _get_distribution_strategy does not exist.
    if hasattr(self.model, '_get_distribution_strategy'):
      # TensorBoard callback involves writing a summary file in a
      # possibly distributed settings.
      self._log_write_dir = distributed_file_utils.write_dirpath(
          self.log_dir, self.model._get_distribution_strategy())  # pylint: disable=protected-access
    else:
      self._log_write_dir = self.log_dir

# 1732行左右也要改一下: # distributed_file_utils.remove_temp_dirpath()

    # In case this callback is used via native Keras, _get_distribution_strategy does not exist.
    if hasattr(self.model, '_get_distribution_strategy'):
      # Safely remove the unneeded temp files.
      distributed_file_utils.remove_temp_dirpath(
          self.log_dir, self.model._get_distribution_strategy())  # pylint: disable=protected-access

解决办法B:

修改引用,改为从tensorflow.keras中引用。

import keras

from tensorflow.keras.callbacks import TensorBoard
from tensorflow.keras.layers import *
from tensorflow.keras.models import Sequential

# xxxxx
上一篇下一篇

猜你喜欢

热点阅读