Tensorflow model and calling save

Description : training model, stored parameters, to enter directly upon subsequent verification model validation data set to obtain a simulation result.

The main official reference tutorials and blog https://www.cnblogs.com/hejunlin1992/p/7767912.html

 

1 , the storage model

mymodel.meta ----------- preserved Tensorflow graph of protocol buffer, for example, all of the variables, operations, collections, etc.

mymodel.data-00000-of-00001 ----------.data training file contains variables such as weight (weights), offset (biases), gradient (Gradients) and all other variables saved (variables).

mymodel.index

checkpoint ----------- record storage path to save the latest model.

 

2, save the model

Use tf.train.Saver () class

例:saver=tf.train.Saver(tf.global_variables(),max_to_keep=20)

If you do not specify anything in tf.train.Saver (), save all variables.

If you do not want to save all the variables, just want to save some of the variables, you can create when tf.train.Saver instance, passing it a list or dictionary of the variables you want to save.

 

3, call a model already trained

使用tf.train.import_meta_graph()、saver.restore() 和 tf.get_default_graph()

例:with tf.Session() as sess:

             specified parameters read path # = tf.train.import_meta_graph Saver ( 'train.model-1000.meta')
              saver.restore (Sess, ( 'train.model-1000')) # extract parameters
              graph = tf.get_default_graph ( ) # get the model structure (Figure tensor graph)

             # By the value of the variable name of the variable load

             X=graph.get_tensor_by_name('X:0')

            # Note: If you want to load variables by variable name, the requirements have been saved in the model name indicates the variable variable

 

4, model retraining

 After 3, extracted in the structure and parameters of the model, according to their needs directly writing code model training.

 

Guess you like

Origin www.cnblogs.com/zixuan-L/p/11027675.html