- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
To test the running of a custom tensorflow network on the NCS, I've created a small "hello world" type example (see below). Unfortunately, the NCS gives the incorrect output when running this example.
This example network aims to take an input value, multiply it by itself and add 10.
The following script generates a tensorflow graph (tf_maths.meta file). The script also prints the output values for inputs 0 to 10.
import tensorflow as tf
tf.reset_default_graph()
# Name of the graph
name = 'tf_maths'
# Tensorflow graph that multiplies an input number by itself and adds 10
x = tf.get_variable("input", shape=[1,1], initializer = tf.zeros_initializer, dtype = tf.float16)
x1 = tf.matmul(x, x, name = 'multiply')
v1 = tf.Variable(10.0, name = 'variable1', dtype = tf.float16)
v2 = tf.Variable(0.0, name = 'variable2', dtype = tf.float16)
y = tf.add(x1,v1, name = 'add_variable')
y2 =tf.add(y,v2, name = 'output')
with tf.Session() as sess:
# Initialise variables
init_op = tf.global_variables_initializer()
sess.run(init_op)
# Test with inputs 0 to 10
for i in range(0,11):
assign_op = x.assign([[i]])
sess.run(assign_op)
print('%i, %s' %(i,sess.run(y2)))
# Save the graph
saver = tf.train.Saver(tf.global_variables())
saver.save(sess, './' + name)
I then run the following command to compile the graph, ready for loading on to the NCS.
mvNCCompile tf_maths.meta -in input -on output -s 12 -is 1 1
Finally, I run the following script to load the graph on to the NCS and test the output values with input values 0 to 10.
from mvnc import mvncapi as mvnc
import numpy as np
# get input parameters
graph_path = './graph'
devices = mvnc.EnumerateDevices()
if len(devices) == 0:
print('No devices found')
quit()
device = mvnc.Device(devices[0])
device.OpenDevice()
#Load graph
with open(graph_path, mode='rb') as f:
graphfile = f.read()
#Load preprocessing data
graph = device.AllocateGraph(graphfile)
# Testing numbers 0 to 10
for i in range(0,11):
a = np.array([[i]])
if (graph.LoadTensor(a.astype(np.float16), 'user object')):
output, userobj = graph.GetResult()
print('%i, %s' %(i,output))
else:
print("LoadTensor fail")
print('deallocate graph')
graph.DeallocateGraph()
device.CloseDevice()
print('Finished')
Unfortunately, the output values aren't correct. As shown below:
| input | expected output | NCS output |
|---|---|---|
| 0.0 | 10.0 | 0.0 |
| 1.0| 11.0 | 12.0 |
| 2.0| 14.0 | 24.0 |
| 3.0| 19.0 | 36.0 |
| 4.0| 26.0 | 48.0 |
| 5.0| 35.0 | 60.0 |
| 6.0 | 46.0 | 72.0 |
| 7.0 | 59.0 | 84.0 |
| 8.0 | 74.0 | 96.0 |
| 9.0 | 91.0 | 108.0 |
| 10.0 | 110.0 | 120.0 |
As you can see, the NCS looks to be multiplying the input by 12.0, rather than performing the intended operation. If I create a similar tensorflow graph in which I only do matrix multiplications (no add operations) I do get the correct output.
Is there possibly a bug in the compiler when interpreting a tf.add layer? I'd be very grateful if you could confirm the approach that I am taking to run a custom tensorflow network on the NCS is correct, and if so, the cause of the problem when performing add operations
- Tags:
- Tensorflow
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any comments on this issue would be very much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am also facing same issue. I am getting wrong output when I run in Movidius stick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bump for comment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@tf_movidius If you remove the tf.add layer you also will not get correct results, the problem is elsewhere. The mvNCCompile is working properly with 3 channels input (RGB images) when making graph from tensorflow model. Can you try reworking your TF model to be using 3 channels and test if the TF results match the NCS results then.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page