Forums - Crash log when executing Android MNIST app

3 posts / 0 new
Last post
Crash log when executing Android MNIST app
jungpyo.hong
Join Date: 4 Mar 15
Posts: 3
Posted: Mon, 2017-12-18 20:53

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 tf
from tensorflow.examples.tutorials.mnist import input_data
# === prepare tensorflow network === #
 
#config setting
imageDim = 784
outputDim = 10
 
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
# None means that a dimension can be any of any length
x = tf.placeholder(tf.float32, [None, imageDim], name="input")
 
# 784-dimensional image vectors by it to produce 10-dimensional vectors
W = 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")
 
# softmax
y = tf.nn.softmax(tf.matmul(x, W) + b, name="softmax")
print(x, W, b, y)
 
# input correct answers
y_ = tf.placeholder(tf.float32, [None, outputDim])
 
# cross-entropy
cross_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 variables
saver = tf.train.Saver()
 
print("tensorflow network already prepare done...")
print("session start run...")
with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())
#Training
    for 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 tensorboard
    saver.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/")
 
#Testing
    correct_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();
    }
}
  • Up0
  • Down0
dmarques
Join Date: 15 Sep 17
Posts: 27
Posted: Tue, 2017-12-19 18:56

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.

  • Up0
  • Down0
jungpyo.hong
Join Date: 4 Mar 15
Posts: 3
Posted: Wed, 2017-12-20 19:30

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.

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.