美文网首页TensorFlow技术帖
keras调用tensorborad时报错 AttributeE

keras调用tensorborad时报错 AttributeE

作者: 洗洗睡吧i | 来源:发表于2020-02-22 15:27 被阅读0次

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

    软件版本:

    • python: 3.7.4
    • keras: 2.3.1
    • tensorboard: 2.1.0
    • tensorflow: 2.1.0

    解决办法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.

    • 直接修改tensorflow/python/keras/callbacks.py文件,如下图。

    相关代码如下。

    # 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
    

    相关文章

      网友评论

        本文标题:keras调用tensorborad时报错 AttributeE

        本文链接:https://www.haomeiwen.com/subject/cnulqhtx.html