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

TensorFlow报错:'Sequential'对象无'endswith'属性,求模型保存方案

解决TensorFlow模型保存时的AttributeError: 'Sequential' object has no attribute 'endswith'错误

错误原因

  • 参数传递错误:model.save()的第一个参数应为保存路径,你错误地将model对象本身传入,导致代码把模型实例当作文件路径处理,而Sequential模型对象没有字符串方法endswith,触发报错。
  • 路径格式错误:export_path中添加了多余的转义双引号,会干扰路径的正常识别。

解决方案

1. 修正模型保存代码

调整model.save()的参数顺序,并移除路径中的多余引号:

import time
t = time.time()

# 生成正确的路径字符串,无需额外引号
export_path = "/tmp/saved_models/{}".format(int(t))
# 正确调用save方法:仅传入保存路径
model.save(export_path)

export_path

2. 修复依赖版本兼容性问题

你安装的tensorflow-hub==0.4是针对旧版TensorFlow的版本,建议更新到适配TF2的版本,避免潜在兼容性问题:

!pip uninstall -y tensorflow-hub
!pip install tensorflow-hub

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 09:08:12