Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Alert: Beginning Tuesday, June 25th, we will be freezing this site and migrating the content and forums to our new home at https://forums.intel.com. Check it out now!

Incorrect output with simple custom tensorflow network (tf.add bug?)

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)

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)
device.OpenDevice()

with open(graph_path, mode='rb') as f:

graph = device.AllocateGraph(graphfile)

# Testing numbers 0 to 10

for i in range(0,11):
a = np.array([[i]])

output, userobj = graph.GetResult()
print('%i, %s' %(i,output))
else:

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