Mask R-cnn 代码运行报错总结

环境版本

  • TensorFlow 2.1.0
  • Python 3.7
  • keras 2.3.1

1. 数据集下载与参数配置

2. 运行报错开始

报错1

  • AttributeError: module 'tensorflow' has no attribute 'random_shuffle'
  • random_shuffle改为random.shuffle
    在这里插入图片描述

报错2

  • AttributeError: module 'tensorflow' has no attribute 'log''
  • log改为math.log
    在这里插入图片描述
    在这里插入图片描述

报错3

  • AttributeError:‘str’ object has no sttribute decode
  • h5py版本太高,降低版本
    pip install h5py==2.10.0
    

报错4

  • tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
  • 修改
    在这里插入图片描述

报错5

  • AttributeError: ‘Model’ object has no attribute ‘metrics_tensors’
  • 修改,添加代码self.keras_model.metrics_tensors = []
    在这里插入图片描述

报错6

  • AttributeError: ‘Model’ object has no attribute ‘_get_distribution_strategy’

  • 修改文件..\Lib\site-packages\tensorflow_core\python\keras\callbacks.py【自己找自己环境位置】

  • 修改代码

        # 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
    
    
    • 修改前文件在这里插入图片描述
    • 修改后文件
      在这里插入图片描述
  • 修改代码

       # 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
    
    • 修改前文件在这里插入图片描述
      修改后文件
      在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_46926492/article/details/129321427