The rate of consumption for the conservation and restoration of the tensor

I trained a model with a serial norm in Tensorflow. I would like to save the model and restore it for future use. The dosage rate is performed using

def batch_norm(input, phase):
    return tf.layers.batch_normalization(input, training=phase)

where is the phase Trueduring training and Falseduring testing.

It seems like just calling

saver = tf.train.Saver()
saver.save(sess, savedir + "ckpt")

will not work, because when I restore the model, it first says that the restoration completed successfully. He also says Attempting to use uninitialized value batch_normalization_585/betaif I just ran one node on the chart. Is this due to the fact that I did not save the model correctly or something else that I missed?

+4
source share
2 answers

" batch_normalization_585/beta". - , , , :

         saver = tf.train.Saver() 

, tf.trainable_variables(), . ckpt, :

         saver = tf.train.Saver(tf.global_variables())

, . , avg , , :

         saver = tf.train.Saver(tf.trainable_variables() + list_of_extra_variables)
+2

, , ( ).

, TensorFlow, node. , . node, , TensorFlow ( , ). , , , Add, , , - Add_2. node, . ; , tf.layers.batch_normalization beta gamma.

:

  • , . , .
  • , , , .
  • save saver, .
  • ( Python , ). , .
  • restore .

, .

TensorFlow batch_normalization_585/beta. , tf.layers.batch_normalization 600 , beta. , , , , API , .

-, :

import tensorflow as tf

def make_model():
    input = tf.placeholder(...)
    phase = tf.placeholder(...)
    input_norm = tf.layers.batch_normalization(input, training=phase))
    # Do some operations with input_norm
    output = ...
    saver = tf.train.Saver()
    return input, output, phase, saver

# We work with one graph first
g1 = tf.Graph()
with g1.as_default():
    input, output, phase, saver = make_model()
    with tf.Session() as sess:
        # Do your training or whatever...
        saver.save(sess, savedir + "ckpt")

# We work with a second different graph now
g2 = tf.Graph()
with g2.as_default():
    input, output, phase, saver = make_model()
    with tf.Session() as sess:
        saver.restore(sess, savedir + "ckpt")
        # Continue using your model...

, , , , Python , . , (, , node) .

+1

Source: https://habr.com/ru/post/1684140/


All Articles