bojone / oppo-text-match

小布助手对话短文本语义匹配的一个baseline
139 stars 32 forks source link

关于weights转ckpt模型 #5

Open guowhite opened 3 years ago

guowhite commented 3 years ago

你好,我在用build_transformer_model初始化后,再load_weights,使用了save_weights_as_checkpoint方法想要进行权重转换,但是会报错Model object has no attribute save_weights_as_checkpoint,请问怎么才能实现转成ckpt权重文件呢

bojone commented 3 years ago

load_weights和save_weights是keras的方法,save_weights_as_checkpoint和load_weights_from_checkpoint是bert4keras的方法,Model没有save_weights_as_checkpoint是显然成立的事情。

只要稍加理解keras和bert4keras的关系,查看一下build_transformer_model的源码,就能写出了:

bert = build_transformer_model(xxx, return_keras_model=False)
model = bert.model
model.load_weights(xxxxxx)
bert.save_weights_as_checkpoint(xxxxx)
guowhite commented 3 years ago

啊明白了 十分感谢!