Hi,
I got crash log when I executed MNIST application using SNPE on LG V30.
Could you let me know the reason of crash log?
com.qualcomm.qti.snpe.NeuralNetwork$InvalidInput: Tensor not amongst network input tensors: input
I proceeded sequentially as follows.
[ 1. minist tensorflow source code ]
import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data# === prepare tensorflow network === ##config settingimageDim = 784outputDim = 10mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)# None means that a dimension can be any of any lengthx = tf.placeholder(tf.float32, [None, imageDim], name="input")# 784-dimensional image vectors by it to produce 10-dimensional vectorsW = tf.Variable(tf.zeros([imageDim, outputDim]), dtype=tf.float32, name="Weight")# a shape of [10]b = tf.Variable(tf.zeros([outputDim]), dtype=tf.float32, name="bias")# softmaxy = tf.nn.softmax(tf.matmul(x, W) + b, name="softmax")print(x, W, b, y)# input correct answersy_ = tf.placeholder(tf.float32, [None, outputDim])# cross-entropycross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)# Add ops to save and restore all the variablessaver = tf.train.Saver()print("tensorflow network already prepare done...")print("session start run...")with tf.Session() as sess:sess.run(tf.initialize_all_variables())#Trainingfor i in range(1000):if i % 100 == 0:print("iteration num :", i)batch_xs, batch_ys = mnist.train.next_batch(100)sess.run(train_step,feed_dict={x: batch_xs, y_: batch_ys})# Save checkpoint, graph.pb and tensorboardsaver.save(sess, "models/model.ckpt")tf.train.write_graph(sess.graph.as_graph_def(), "models/", "graph.pb")tf.summary.FileWriter("board", sess.graph)print("ckpt model save in the file : models/model.ckpt")print("graph model save in the file : models/graph.pb")print("board model save in the directory : board/")#Testingcorrect_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))print("accuracy : ",sess.run(accuracy,feed_dict={x: mnist.test.images, y_:mnist.test.labels}))
[ 2. create frozen graph and dlc file ]
$ python freeze_graph.py --input_graph models/graph.pb --input_checkpoint models/model.ckpt --output_graph models/frozen_graph.pb --output_node_names softmax
$ snpe-tensorflow-to-dlc --graph models/frozen_graph.pb --input_dim input 784 --dlc mnist.dlc --out_node softmax
$ snpe-dlc-quantize --input_dlc mnist.dlc --input_list image_list.txt --output_dlc mnist_quantized.dlc
[ 3. mnist application source code ]
package cmc.snpe_mnist;import android.app.Activity;import android.app.Application;import android.content.Context;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.util.HashMap;import java.util.Map;import com.qualcomm.qti.snpe.FloatTensor;import com.qualcomm.qti.snpe.NeuralNetwork;import com.qualcomm.qti.snpe.SNPE;public class DigitDetector {private SNPE.NeuralNetworkBuilder builder = null;private NeuralNetwork network = null;private File file = null;private int[] results;public int detectDigit(int[] pixels) {final FloatTensor tensor = network.createFloatTensor(784);float[] floatArray = new float[pixels.length];for (int i = 0; i < pixels.length; i++) {floatArray[i] = (float)pixels[i];}tensor.write(floatArray, 0, floatArray.length);final Map<String, FloatTensor> inputs = new HashMap<>();inputs.put("input", tensor);final Map<String, FloatTensor> outputs = network.execute(inputs);for (Map.Entry<String, FloatTensor> output : outputs.entrySet()) {final FloatTensor out_tensor = output.getValue();final float[] values = new float[out_tensor.getSize()];tensor.read(values, 0, values.length);for (int j = 0; j < values.length; j++) {results[j] = (int)values[j];}}return results[0];}public boolean setup(Context context) {Activity activity = (Activity)context;Application application = (Application)activity.getApplication();try {InputStream inputStream = context.getResources().openRawResource(R.raw.mnist);builder = new SNPE.NeuralNetworkBuilder(application).setRuntimeOrder(/*NeuralNetwork.Runtime.DSP,*/ NeuralNetwork.Runtime.GPU, NeuralNetwork.Runtime.CPU).setModel(inputStream, inputStream.available());//file = new File(context.getDataDir(), "models/mnist.dlc");//builder = new SNPE.NeuralNetworkBuilder(application)// .setRuntimeOrder(NeuralNetwork.Runtime.DSP, NeuralNetwork.Runtime.GPU, NeuralNetwork.Runtime.CPU)// .setModel(file);} catch (IOException e) {e.printStackTrace();return false;}network = builder.build();return true;}public void unset() {network.release();}}
What is the name of the input layer when you execute snpe-dlc-info ? Seems like the name generated for the layer is different from your placeholder name.
Placeholder name of input layer is "input".
I confirmed that input node name is "input:0" by snpe-dlc-info.
MNIST app was working when I changed node name to "input:0".
Thanks.