【tensorflow】module ‘tensorflow.python.keras.utils.generic_utils‘ has no attribute populate_dict_with

遇到这个问题

参考:https://stackoverflow.com/posts/61347413/edit
module ‘tensorflow.python.keras.utils.generic_utils’ has no attribute ‘populate_dict_with_module_objects’

  • 解决办法1:pip install tensorflow==2.1.0
  • 解决办法2:copy “populate_dict_with_module_objects” function from this link (line 1162 to 1167) and add it to “generic_utils.py”
    【注】由于这是github上源码,指定的函数可能会发生改变,因为作者可能有更新,所以行数是参考,重点是找到对应的函数名;

链接里面的代码复制到generic_utils.py文件里。
这是因为原本的 generic_utils.py没有这个函数, 复制下面代码添加到本地的generic_utils.py模块里; 或者将连接里的整个文件下载到本地替换本地的文件!

def populate_dict_with_module_objects(target_dict, modules, obj_filter):
  for module in modules:
    for name in dir(module):
      obj = getattr(module, name)
      if obj_filter(obj):
        target_dict[name] = obj

【tensorflow】module ‘tensorflow.python.keras.utils.generic_utils‘ has no attribute populate_dict_with

对应你使用的tensorflow下的keras对应的位置;

方法2总结:由报错提示说明generic_utils.py文件内没有populate_dict_with_module_objects模块;所以这个解决办法是更新generic_utils.py这个文件(文件在本地)
更新方法1:就是在github源代码里面找到这个函数复制这个函数添加到本地的generic_utils.py模块里
更新方法2:直接全选复制这个链接里面的代码,替换掉本地的generic_utils.py里面的代码并保存

  • 解决办法3:TensorFlow卸载重装

注解:我使用解决方法一成功解决!

Original: https://www.cnblogs.com/Jucw/p/16216579.html
Author: jucw
Title: 【tensorflow】module ‘tensorflow.python.keras.utils.generic_utils‘ has no attribute populate_dict_with

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/563385/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球