admin管理员组文章数量:1794759
'Model'object has no attribute '
先给出笔者的tensorflow和keras版本 如题,笔者在用别人的代码的时候出现了’Model’object has no attribute '_get_distribution_strategy’的错误,百度半天也没有找到解决方案,只知道貌似是版本不同导致的。由于笔者是在anaconda下配置tensorflow和keras的,下文仅提供在此前提下的一种解决方案(不一定可行,尝试前请先备份!笔者的友人在windows上修改后还是失败,报了另一种错误): 先进入anaconda的安装目录,进入lib/site-packages/tensorflow_core/python/keras,编辑callbacks.py(先备份!),把1529行开始的
# 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修改为
# 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再将1730行左右开始的
# Safely remove the unneeded temp files. distributed_file_utils.remove_temp_dirpath( self.log_dir, self.model._get_distribution_strategy()) # pylint: disable=protected-access修改为
# 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保存,再次运行就不再报这个错误了报另一种错,确信
本文讲得不清楚的可以参考github/tensorflow/tensorflow/pull/34870 或者直接看github/tensorflow/tensorflow/pull/34870/commits/0d31c0bee8a1e06c7b4fa977ce2bc6ce347aa96f
版权声明:本文标题:'Model'object has no attribute ' 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686590317a85150.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论