TensorFlow - imports metagraph and uses variables from it

I study CNN classification with TensorFlow v0.12 and then want to create labels for new data using a trained model.

At the end of the training script, I added these lines of code:

saver = tf.train.Saver()
save_path = saver.save(sess,'/home/path/to/model/model.ckpt')

After completing the training, the files in the folder are as follows: 1. control point; 2. model.ckpt.data-00000-of-00001; 3. model.ckpt.index; 4. model.ckpt.meta p>

Then I tried to restore the model using the .meta file. Following this tutorial , I added the following line to my classification code:

saver=tf.train.import_meta_graph(savepath+'model.ckpt.meta') #line1

and then:

saver.restore(sess, save_path=savepath+'model.ckpt') #line2

Before this change, I needed to plot the graph again, and then write (instead of line1):

saver = tf.train.Saver()

, line1, , . , , :

predictions = sess.run(y_conv, feed_dict={x: patches,keep_prob: 1.0})

y_conv. ? , , ?

, , . ...

, , ! Roi.

+4
2

, . , , :

saver = tf.train.import_meta_graph('model/export/{}.meta'.format(model_name))
saver.restore(sess, 'model/export/{}'.format(model_name))
graph = tf.get_default_graph()       
y_conv = graph.get_operation_by_name('y_conv').outputs[0]
predictions = sess.run(y_conv, feed_dict={x: patches,keep_prob: 1.0})

, , ops , , . , , :

tf.add_to_collection("y_conv", y_conv)

, metagraph , :

y_conv = tf.get_collection("y_conv")[0]

- , , , , .

Btw, .ckpt, , .

+9

- , :

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

, y_conv name="y_conv" ( TF ops ).

+3

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


All Articles