Issue
I have checkpoint files (meta, index, ckpt) from tensorflow v1. But I don't have any code like create_model so I can't load model in tensorflow v2, and load wegiths.
Is there any way to get model and load weight together in Tensorflow v2 with these files?
I found some functions like 'builder.add_meta_graph_and_variables', 'tf.saved_model.simple_save' but I think it's not useful to me.
And I tried to convert ckpt, meta to pb, and pb to h5 file but I think it's impossible.
Is there any way to use version 1 checkpoint file at version2?
Solution
I used tensorflow.compat.v1
with tensorflow v2 and I was able to use tensorflow v1 resources.
model_path
is tensorflow v1 checkout path.
I needed to find tensor name of model ("X:0", "is_trainig:0", "prob:0").
import tensorflow.compat.v1 as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
class Model:
def __init__(self, model_path, model_name):
self.graph = tf.Graph()
self.sess = tf.Session(graph=self.graph, config=config)
with self.graph.as_default():
saver = tf.train.import_meta_graph(os.path.join(model_path, "{}.meta".format(model_name)))
saver.restore(self.sess, os.path.join(model_path, model_name))
self.X = self.graph.get_tensor_by_name("X:0")
self.is_training = self.graph.get_tensor_by_name("is_training:0")
self.prob = self.graph.get_tensor_by_name("prob:0")
Answered By - Lazyer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.