convert tensorflow .pb to .dlc fail with snpe

2.4k Views Asked by At

I save the graph to a .pb file. I get an error when I convert the .pb to .dlc. Anyone know why?

My code to build the model:

import tensorflow as tf
from tensorflow.python.framework.graph_util import convert_variables_to_constants
from tensorflow.python.ops import variable_scope

X = tf.placeholder(tf.float32, shape=[None, 1], name="input");


with variable_scope.variable_scope("input"):
    a = tf.Variable([[1]], name="a", dtype=tf.float32);
    g = X * a


with variable_scope.variable_scope("output"):
    b = tf.Variable([[0]], name="b", dtype=tf.float32);
    ss = tf.add(g, b, name="output")


sess = tf.Session();
sess.run(tf.global_variables_initializer());


graph = convert_variables_to_constants(sess, sess.graph_def, ["output/output"])
tf.train.write_graph(graph, './linear/', 'graph.pb', as_text=False)

sess.close();

convert cmd:

snpe-tensorflow-to-dlc --graph graph_sc.pb -i input 1 --out_node output/output --allow_unconsumed_nodes

error message:

2017-10-26 01:55:15,919 - 390 - INFO - INFO_ALL_BUILDING_LAYER_W_NODES: Building layer (ElementWiseMul) with nodes: [u'input_1/mul']

~/snpe-sdk/snpe-1.6.0/lib/python/converters/tensorflow/layers/eltwise.py:108: RuntimeWarning: error_code=1002; error_message=Layer paramter value is invalid. Layer input_1/mul: at least two inputs required, have 1; error_component=Model Validation; line_no=732; thread_id=140514161018688
  output_name)

2017-10-26 01:55:15,920 - 390 - INFO - INFO_ALL_BUILDING_LAYER_W_NODES: Building layer (ElementWiseSum) with nodes: [u'output/output']

~/snpe-sdk/snpe-1.6.0/lib/python/converters/tensorflow/layers/eltwise.py:84: RuntimeWarning: error_code=1002; error_message=Layer paramter value is invalid. Layer output/output: at least two inputs required, have 1; error_component=Model Validation; line_no=732; thread_id=140514161018688
  output_name)
2

There are 2 best solutions below

0
On

SNPE requires a 3D tensor as input. Try to update your command -i input 1 to -i input 1,1,1

1
On

The input_dim argument to snpe-tensorflow-to-dlc should be of 3 dimension tensors like below example,

snpe-tensorflow-to-dlc --graph $SNPE_ROOT/models/inception_v3/tensorflow/inception_v3_2016_08_28_frozen.pb
                       --input_dim input "1,299,299,3" --out_node "InceptionV3/Predictions/Reshape_1" --dlc inception_v3.dlc
                       --allow_unconsumed_nodes

For more detailed reference to convert TensorFlow model to DLC using Neural Processing SDK follow below link, https://developer.qualcomm.com/docs/snpe/model_conv_tensorflow.html