Skip to content

Build android demo using a custom classifier #7419

Closed
@davideb91

Description

@davideb91

I want build TensorFlow Android Camera Demo using a custom classifier following this tutorial.
When I build the app using bazel build //tensorflow/examples/android:tensorflow_demo I get:

CONFLICT: asset:WORKSPACE is provided with ambiguous priority from:
        external/mobile_multibox/WORKSPACE
        external/inception5h/WORKSPACE
CONFLICT: asset:WORKSPACE is provided with ambiguous priority from:
        external/stylize/WORKSPACE
        external/mobile_multibox/WORKSPACE

Thanks in advance!

Activity

andrewharp

andrewharp commented on Feb 10, 2017

@andrewharp
Contributor

@davideb91 That article is somewhat outdated. The model files are now downloaded automatically by Bazel, which is why you're getting conflicts with the manually downloaded ones. You can either delete the files from assets/, or remove the dependencies on the file archives in the tensorflow/examples/android/BUILD file.

davideb91

davideb91 commented on Feb 10, 2017

@davideb91
Author

Thanks @andrewharp , it works now!
However when I try to open the app on my android phone it is terminated.

To build the app I ran

$ bazel-bin/tensorflow/python/tools/optimize_for_inference \
--input=tf_files/retrained_graph.pb \
--output=tensorflow/examples/android/assets/retrained_graph.pb
--input_names=Mul \
--output_names=final_result

in order to optimize my graph, and I copied retrained_label.txt in /android/assets/ .
Then I added these line in /tensorflow/tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowImageClassifier.java

private static final int INPUT_SIZE = 299;
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
private static final String INPUT_NAME = "Mul:0";
private static final String OUTPUT_NAME = "final_result:0";

private static final String MODEL_FILE = "file:///android_asset/retrained_graph.pb";
private static final String LABEL_FILE = "file:///android_asset/retrained_labels.txt";

And I removed other dependencies on the file archives in the tensorflow/examples/android/BUILD file:

    assets = [
        "//tensorflow/examples/android/assets:asset_files",
#        "@inception5h//:model_files",
#        "@mobile_multibox//:model_files",
#        "@stylize//:model_files",
    ]

When I build my app with bazel build //tensorflow/examples/android:tensorflow_demo, it works correctly, but when I try to open the app on my phone, it gives error and is terminated.

Do you have any suggestion please?
Thank you very much!

andrewharp

andrewharp commented on Feb 10, 2017

@andrewharp
Contributor

@davideb91 What does adb logcat say?

davideb91

davideb91 commented on Feb 11, 2017

@davideb91
Author

@andrewharp This is the output of adb logcat:

02-11 15:49:40.331 15832 15832 I TensorFlowImageClassifier: Reading labels from: imagenet_comp_graph_label_strings.txt
02-11 15:49:40.351 15832 15832 E AndroidRuntime: FATAL EXCEPTION: main
02-11 15:49:40.351 15832 15832 E AndroidRuntime: Process: org.tensorflow.demo, PID: 15832
02-11 15:49:40.351 15832 15832 E AndroidRuntime: java.lang.RuntimeException: Error initializing TensorFlow!
02-11 15:49:40.351 15832 15832 E AndroidRuntime: at org.tensorflow.demo.ClassifierActivity.onPreviewSizeChosen(ClassifierActivity.java:135)
02-11 15:49:40.351 15832 15832 E AndroidRuntime: at org.tensorflow.demo.CameraActivity$1.onPreviewSizeChosen(CameraActivity.java:158)
02-11 15:49:40.351 15832 15832 E AndroidRuntime: at org.tensorflow.demo.CameraConnectionFragment.setUpCameraOutputs(CameraConnectionFragment.java:394)
02-11 15:49:40.351 15832 15832 E AndroidRuntime: at org.tensorflow.demo.CameraConnectionFragment.openCamera(CameraConnectionFragment.java:411)
02-11 15:49:40.351 15832 15832 E AndroidRuntime: at org.tensorflow.demo.CameraConnectionFragment.access$000(CameraConnectionFragment.java:63)
02-11 15:49:40.351 15832 15832 E AndroidRuntime: at org.tensorflow.demo.CameraConnectionFragment$1.onSurfaceTextureAvailable(CameraConnectionFragment.java:94)
andrewharp

andrewharp commented on Feb 11, 2017

@andrewharp
Contributor

Is the label file actually in your assets folder?

davideb91

davideb91 commented on Feb 13, 2017

@davideb91
Author

@andrewharp In asset folder (tensorflow/tensorflow/examples/android/asset) there are only label and graph file of my retrained model, and I haven't found any file named imagenet_comp_graph_label_strings.txt in tensorflow/*.
With a grep command I found the string ("imagenet_comp_graph_label_strings.txt") in these files:

tensorflow/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java
tensorflow/tensorflow/core/kernels/hexagon/hexagon_graph_execution_test.cc
tensorflow/tensorflow/contrib/ios_examples/.gitignore
tensorflow/tensorflow/contrib/ios_examples/benchmark/benchmark.xcodeproj/project.pbxproj
tensorflow/tensorflow/contrib/ios_examples/simple/tf_ios_makefile_example.xcodeproj/project.pbxproj
tensorflow/tensorflow/contrib/ios_examples/camera/camera_example.xcodeproj/project.pbxproj
tensorflow/tensorflow/contrib/pi_examples/label_image/label_image.cc
tensorflow/tensorflow/contrib/pi_examples/.gitignore
tensorflow/tensorflow/contrib/pi_examples/camera/camera.cc
tensorflow/tensorflow/examples/label_image/main.cc
tensorflow/tensorflow/examples/android/src/org/tensorflow/demo/ClassifierActivity.java

Could one of these files be the problem?

davideb91

davideb91 commented on Feb 13, 2017

@davideb91
Author

Solved!
Problem was in tensorflow/tensorflow/examples/android/src/org/tensorflow/demo/ClassifierActivity.java
I had to set dependencies to my model.
Thanks Andrew for help

andrewharp

andrewharp commented on Feb 13, 2017

@andrewharp
Contributor

Great!

AnSharypov

AnSharypov commented on Feb 18, 2017

@AnSharypov

@davideb91 I heave the same problem. Can you please say - which dependencies you set?

davideb91

davideb91 commented on Feb 20, 2017

@davideb91
Author

@AnSharipov I set these dependencies in tensorflow/tensorflow/examples/android/src/org/tensorflow/demo/ClassifierActivity.java :

  private static final int NUM_CLASSES = 1008;
  private static final int INPUT_SIZE = 299;
  private static final int IMAGE_MEAN = 128;
  private static final float IMAGE_STD = 128;
  private static final String INPUT_NAME = "Mul:0";
  private static final String OUTPUT_NAME = "final_result:0";
  private static final String MODEL_FILE = "file:///android_asset/retrained_graph.pb";
  private static final String LABEL_FILE = "file:///android_asset/retrained_labels.txt";
abhigoku10

abhigoku10 commented on Oct 17, 2017

@abhigoku10

@davideb91 can u pls explain what are these parameters and how to set these values , since i have trained the model in darknet and converted using darkflow
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
private static final String INPUT_NAME = "Mul:0";
private static final String OUTPUT_NAME = "final_result:0";

sepulm01

sepulm01 commented on Jun 23, 2018

@sepulm01

Hi @davideb91 and @andrewharp

I'm working in a street object clasification project. I would like to know if the performance is better if I'll train only a few categories (cars, trucks, bus, pedestrian...) than use a COCO .pb database. Do you test it ? Best regards.
Martin

SheezaShabbir

SheezaShabbir commented on Jul 5, 2018

@SheezaShabbir

Gyz I also working on the same project with same model but my own dataset. But facing same error.My app is running but not giving labeling for the images.Do not know what to do. Please help... I also change dependencies as given above but its not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @girving@andrewharp@AnSharypov@abhigoku10@davideb91

      Issue actions

        Build android demo using a custom classifier · Issue #7419 · tensorflow/tensorflow