Neural network weight export using tensor flow

I wrote a neural network using tensor flow tools. everything works, and now I want to export the final weights of my neural network in order to create a single forecasting method. How can i do this?

+3
source share
2 answers

You will need to save your model at the end of training using the class tf.train.Saver.

When initializing an object, Saveryou need to pass a list of all the variables that you want to save. The best part is that you can use these saved variables in another calculation graph!

Saver,

# Assume you want to save 2 variables `v1` and `v2`
saver = tf.train.Saver([v1, v2])

tf.Session,

saver.save(sess, 'filename');

, , global_step.

restore(). .

+2

- / . , tenorflow, .

. TF . :

#!/bin/bash -x

# The script combines graph definition and trained weights into
# a single binary protobuf with constant holders for the weights.
# The resulting graph is suitable for the processing with other tools.


TF_HOME=~/tensorflow/

if [ $# -lt 4 ]; then
    echo "Usage: $0 graph_def snapshot output_nodes output.pb"
    exit 0
fi

proto=$1
snapshot=$2
out_nodes=$3
out=$4

$TF_HOME/bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=$proto \
    --input_checkpoint=$snapshot \
    --output_graph=$out \
    --output_node_names=$out_nodes 

, .

0

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


All Articles