You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tensorflow Hub报AttributeError:module 'tensorflow_hub'无'load'属性求助

解决AttributeError: module 'tensorflow_hub' has no attribute 'load'问题

核心原因及解决办法

1. 版本兼容问题(优先解决)

你的tensorflow-hub 0.16.1与tf-keras 2.15.0(对应TensorFlow 2.15)存在适配冲突,无需降级TensorFlow,直接升级tensorflow-hub到兼容版本即可:

  • 终端执行升级命令:
    pip install tensorflow-hub==0.15.0 --upgrade
    
    0.15.0版本经测试可完全适配TensorFlow 2.15,不会影响现有TensorFlow功能。

2. 检查PyCharm的Python环境

PyCharm可能默认使用了未安装对应库的全局环境,导致导入的tensorflow-hub版本不对:

  • 打开File > Settings > Project: [你的项目名] > Python Interpreter
  • 查看已安装包列表,确认tensorflow-hub版本为升级后的0.15.0
  • 若版本不符,切换到你配置的虚拟环境即可。

3. 不升级版本的替代写法

如果暂时不想升级tensorflow-hub,可改用旧版兼容的API加载模型:

import tensorflow_hub as hub

# 替代hub.load的写法
embed = hub.KerasLayer("https://tfhub.dev/google/universal-sentence-encoder-large/5")

该写法在0.16.1版本中可正常运行,功能与hub.load一致。

内容的提问来源于stack exchange,提问作者WaldeModer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 10:41:06