Forests and tf.train.MonitoredTrainingSession

I was wondering how to use Scaffold with tf.train.MonitoredTrainingSession and have graph weights initialized with specific imported values ​​from a Numpy array. I could not find an explicit example of such use. Thanks

+4
source share
1 answer

So there are actually several ways to do this.

Saving the graph control point approach

  • Build your schedule.
  • Initialize all variables.
  • Starting a session to assign values ​​to each variable.
  • save a breakpoint for loading during training.
  • use breakpoint in train

Using model initialization and recovery

: Tensorflow Model Recovery. , tf.train.Scaffold init_fn init.

, :

  with tf.Graph().as_default():

    # build the graph as it is in training
    some code...

    sess = tf.Session()
    with sess.as_default():

        # Add an op to initialize the variables.
        init_op = tf.global_variables_initializer()
        sess.run(init_op)

        #Update your graph with starting variables
        data_dict = np.load('your_pass/model.npy', encoding='latin1').item()
        #
        var = tf.get_variable(param_name)
        sess.run(var.assign(data_dict))
        print('assignment done!')

    saver = tf.train.Saver()

    # Save the variables to disk.
    save_path = saver.save(sess, FLAGS.train_dir)
    print("Model saved in file: %s" % save_path)    
+2

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


All Articles