bert4keras icon indicating copy to clipboard operation
bert4keras copied to clipboard

model.save() 保存模型时报错

Open dashilu1573 opened this issue 3 years ago • 1 comments

model.save() 保存SavedModel时,报错:

Traceback (most recent call last): File "/Users/luyafei/Downloads/code/DeepTextMatch/SBERT/run.py", line 142, in model.fit(train_generator.forfit(), File "/Users/luyafei/opt/anaconda3/envs/py3-tf2-new/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/Users/luyafei/opt/anaconda3/envs/py3-tf2-new/lib/python3.9/site-packages/keras/layers/serialization.py", line 117, in populate_deserializable_objects LOCAL.ALL_OBJECTS['Functional'] = models.Functional AttributeError: module 'keras.api._v2.keras.models' has no attribute 'Functional'

提问时请尽可能提供如下信息:

基本信息

  • 你使用的操作系统: mac linux下都尝试不行
  • 你使用的Python版本: 3.9
  • 你使用的Tensorflow版本: tf2.9.0
  • 你使用的Keras版本: 2.9.0
  • 你使用的bert4keras版本: v0.11.1
  • 你使用纯keras还是tf.keras: tf.keras
  • 你加载的预训练模型: chinese_wwm_ext_L-12_H-768_A-12

核心代码


        # 6. model fit
        model.fit(train_generator.forfit(),
                  steps_per_epoch=len(train_generator),
                  epochs=epochs,
                  callbacks=[earlystop, checkpoint])

        model.save("../output/savedmodel/")  # SavedModel 格式

输出信息

# 请在此处贴上你的调试输出

自我尝试

不管什么问题,请先尝试自行解决,“万般努力”之下仍然无法解决再来提问。此处请贴上你的努力过程。

dashilu1573 avatar Mar 01 '23 06:03 dashilu1573

这么新的tf和keras我无能为力啊,抱歉。

bojone avatar Mar 24 '23 02:03 bojone