Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何将模型保存为RoBERTa-wwm那样包含index,meta和data三个文件的checkpoint格式呢? #8

Open
OrangeInSouth opened this issue Jun 18, 2020 · 0 comments

Comments

@OrangeInSouth
Copy link

如题,我该如何将模型保存为RoBERTa-wwm那样包含index,meta和data三个文件的checkpoint格式呢?

目前尝试过save_weights和tf.keras.callbacks.ModelCheckpoint,但是最终都只会输出一个文件。

使用tf.keras.callbacks.ModelCheckpoint保存模型的代码如下:

checkpoint_path = "models/cp-{epoch:04d}.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)

# Create a callback that saves the model's weights
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
                                                 save_weights_only=False,
                                                 verbose=1)

model.fit_generator(
    DataGenerator(train_data_path,batch_size),
    epochs=epochs,
    callbacks=[evaluator, cp_callback],
    verbose = 1
)

最终只生成一个ckpt文件。

-------------------------问题2-------------------
还有一个很困惑的问题,模型使用的是Bert4Keras,那么创建出来的模型应该是bert4keras.bert.BertModel类型,但是我将最终模型的类型打印出来:
print(type(model))
输出为:
<class 'keras.engine.training.Model'>
十分不解,恳请指教!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant