Guidance for Compiling TensorFlow-Slim Networks
If you are compiling a TensorFlow-Slim network for use with the Intel® Movidius™ Neural Compute SDK (Intel® Movidius™ NCSDK) and Neural Compute API, you can follow these steps.
The code below shows how you can save a TensorFlow™ session with graph and checkpoint information.
import numpy as np
import tensorflow as tf
from tensorflow.contrib.slim.nets import inception
slim = tf.contrib.slim
def run(name, image_size, num_classes):
with tf.Graph().as_default():
image = tf.placeholder("float", [1, image_size, image_size, 3], name="input")
with slim.arg_scope(inception.inception_v1_arg_scope()):
logits, _ = inception.inception_v1(image, num_classes, is_training=False, spatial_squeeze=False)
probabilities = tf.nn.softmax(logits)
init_fn = slim.assign_from_checkpoint_fn('inception_v1.ckpt', slim.get_model_variables('InceptionV1'))
with tf.Session() as sess:
init_fn(sess)
saver = tf.train.Saver(tf.global_variables())
saver.save(sess, "output/"+name)
run('inception-v1', 224, 1001)
The is_training=False
parameter is important. This will leave out training-only layers (which aren’t supported by the NCSDK) from the network.
Next, use the NCSDK mvNCCompile tool to compile the saved session from the above code sample for use with the NCSDK and Neural Compute API:
mvNCCompile output/inception-v1.meta -in=input -on=InceptionV1/Logits/Predictions/Reshape_1 -s 12