Forums - Incorrect image classification when tensor flow used in given android example

17 posts / 0 new
Last post
Incorrect image classification when tensor flow used in given android example
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Mon, 2017-08-14 07:04

HI,

Given code at /snpe-1.2.2/examples/android/image-classifiers was modifed to work for tensor flow model inception_v3.

Following are the three changes done in ClassifyImageTask.java to make it work for tensorflow model

1. while createFloatTensor

final FloatTensor tensor = mNeuralNetwork.createFloatTensor( mNeuralNetwork.getInputTensorsShapes().get("Mul:0"));

2. while creating input to execute 

inputs.put("Mul:0", tensor);

3. chaged string OUTPUT_LAYER

public static final String OUTPUT_LAYER = "softmax:0";

 

The script file setup_models.sh was also modified to copy from correct location:

cp -R ../../../../models/inception_v3/data/cropped/*.jpg images
cp -R ../../../../models/inception_v3/dlc/inception_v3_quantized.dlc model.dlc
cp -R ../../../../models/inception_v3/data/imagenet_comp_graph_label_strings.txt labels.txt

Mean image bin file was not created so it was not included in the script.

After doing all above changes the app is classifying images incorrectly. The label index generated from topK() function are not matching with the labels.txt. Please let me know if anything is wrong with my procedure

 

  • Up0
  • Down0
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Mon, 2017-08-21 04:49

Please help solve the above mentioned problem

  • Up0
  • Down0
PeterLee
Join Date: 14 Aug 17
Posts: 2
Posted: Thu, 2017-08-24 19:56

Facing the same issue here, will appreciate for any help on this.

  • Up0
  • Down0
Maggie
Join Date: 1 Aug 17
Posts: 8
Posted: Sun, 2017-08-27 18:47

I am facing the same issue now. I should appreciate it if you could reply as soon as possible.

  • Up0
  • Down0
852105446
Join Date: 15 Aug 17
Posts: 2
Posted: Wed, 2017-11-08 19:35

met the  same  issue for snpe 1.6.0

  • Up0
  • Down0
dmarques
Join Date: 15 Sep 17
Posts: 27
Posted: Thu, 2017-11-09 06:54

You are likely missing image pre-processing such as mean subraction ?

  • Up0
  • Down0
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Fri, 2017-11-10 02:38

"You are likely missing image pre-processing such as mean subraction ?"

As per the documentation "input_preprocessing.html"

-->These image preprocessing operations are currently only supported for DLC networks converted from a Caffe model.

Plese let me know how the same can be acheived for tensorflow model.

One more Observation:

If we follow the documentation "tutorial_inceptionv3.html" for Running on Android topic, we get correct image classification!!.....It gives wrong classification only when running via android studio using java apis. Is there something wrong with java apis or some more process has to be follwed when running via android studio.

 

 

 

  • Up0
  • Down0
dmarques
Join Date: 15 Sep 17
Posts: 27
Posted: Fri, 2017-11-10 04:04

Inception v3 requires the inputs to be preprocessed so you must either generate a mean image file (which the sample will handle) or write code to do preprocessing in the application.

You can find preprocessing for inception v3 as a reference in the <SDK-ROOT>/models/inception_v3/scripts/create_inceptionv3_raws.py

Cheers,

  • Up0
  • Down0
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Mon, 2017-11-13 00:15

I am following the sample provided in the SDK. I have run the command 

python ./models/inception_v3/scripts/setup_inceptionv3.py -a ./temp-assets-cache -d

where preprocessing is being done already.

But mean Image file "ilsvrc_2012_mean_cropped.binis not generated as it happens in alexnet. Is this the problem because this file is being used in ClassifyImageTask.java in method loadMeanImageIfAvailable().

Please help fixing the issue.

 

Thanks,

  • Up0
  • Down0
zhangguangjin
Join Date: 13 Nov 17
Posts: 2
Posted: Mon, 2017-11-13 21:56

I meet the same issue

  • Up0
  • Down0
dmarques
Join Date: 15 Sep 17
Posts: 27
Posted: Tue, 2017-11-14 10:24

You can not use the alexnet scripts for inception v3.

Before you send an image buffer to SNPE you must preprocess according to the network requirements. Look for inception v3 preprocessing requirements and either create a mean binary image or change the sample code to do it in the application before sending to SNPE.

 

  • Up0
  • Down0
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Mon, 2017-11-20 05:43

please provide some reference or document for creating mean binary image for inception_v3

  • Up0
  • Down0
jesliger
Join Date: 6 Aug 13
Posts: 75
Posted: Mon, 2017-11-20 06:10

Hi.  The inceptionv3 example shows how to create raw images for inception V3.

$SNPE_ROOT/models/inception_v3/scripts/create_inceptionv3_raws.py

  • Up0
  • Down0
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Mon, 2017-11-20 20:17

Hi,

As I have already mentioned, I am using script setup_inceptionv3.py. This script already uses create_inceptionv3_raws.py internally. This script does not work!!

  • Up0
  • Down0
dmarques
Join Date: 15 Sep 17
Posts: 27
Posted: Tue, 2017-11-21 06:25

Try modifying the method writeRgbBitmapAsFloat in java/com/qualcomm/qti/snpe/imageclassifiers/tasks/ClassifyImageTask.java

There do the preprocessing for inception v3 on every RGB element of the image before forward propagating. Change the sample so it doesnt use the mean image file and do the preprocessing in place.

Can you post exactly what preprocessing you intend to use on each RGB element so we double check?

Thanks,

  • Up0
  • Down0
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Thu, 2017-12-14 05:38
  • Up0
  • Down0
vivek10.gupta
Join Date: 27 Jul 17
Posts: 11
Posted: Thu, 2017-12-14 05:38
  • 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.