bert icon indicating copy to clipboard operation
bert copied to clipboard

Saving a model after pretraining on custom data.

Open johnny-brav0 opened this issue 4 years ago • 4 comments

Currently, after running the run_pretraining.py the model checkpoints get saved. But is there any way I can save the entire model as a model.pb file so that in future it could be loaded directly as a KerasLayer with tf_hub?

Or is there a way of loading model.ckpt as a KerasLayer?

Please let me know if there is a way to do either. It'd be very helpful.

Thanks.

johnny-brav0 avatar Jan 09 '22 19:01 johnny-brav0

Currently, after running the run_pretraining.py the model checkpoints get saved. But is there any way I can save the entire model as a model.pb file so that in future it could be loaded directly as a KerasLayer with tf_hub?

Or is there a way of loading model.ckpt as a KerasLayer?

Please let me know if there is a way to do either. It'd be very helpful.

Thanks.

patyizsolt avatar Feb 01 '22 06:02 patyizsolt

I don't know the way for converting it to a model.pb, but for the people that find this issue. You can use https://huggingface.co/docs/transformers/converting_tensorflow_models to convert tensorflow checkpoints into pytorch_model.bin

gerwindekruijf avatar May 14 '22 10:05 gerwindekruijf

@theProcrastinatr I think you can do like this

Save the entire model as a SavedModel.

!mkdir -p saved_model model.save('saved_model/my_model')

my_model directory

ls saved_model

Contains an assets folder, saved_model.pb, and variables folder.

ls saved_model/my_model

ritikranjan12 avatar Aug 17 '22 13:08 ritikranjan12

Currently, after running the run_pretraining.py the model checkpoints get saved. But is there any way I can save the entire model as a model.pb file so that in future it could be loaded directly as a KerasLayer with tf_hub?

Or is there a way of loading model.ckpt as a KerasLayer?

Please let me know if there is a way to do either. It'd be very helpful.

Thanks.

Rush97234 avatar May 22 '23 03:05 Rush97234