Created
June 18, 2019 02:38
-
-
Save wfng92/ed5d5b10d06c2349b05cfc975d6efe96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import os | |
#path that contains all 3 ckpt files of your fine-tuned model | |
path = './bert_output' | |
#path to output the new optimized model | |
output_path = os.path.join(path, 'optimized_model') | |
sess = tf.Session() | |
imported_meta = tf.train.import_meta_graph(os.path.join(path, 'model.ckpt-236962.meta')) #based on the steps of your fine-tuned model | |
imported_meta.restore(sess, os.path.join(path, 'model.ckpt-236962')) #based on the steps of your fine-tuned model | |
my_vars = [] | |
for var in tf.all_variables(): | |
if 'adam_v' not in var.name and 'adam_m' not in var.name: | |
my_vars.append(var) | |
saver = tf.train.Saver(my_vars) | |
saver.save(sess, os.path.join(output_path, 'model.ckpt')) #change model.ckpt to name of your preference |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment