Skip to content

Build android demo using a custom classifier #7419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davideb91 opened this issue Feb 10, 2017 · 13 comments
Closed

Build android demo using a custom classifier #7419

davideb91 opened this issue Feb 10, 2017 · 13 comments
Assignees
Labels
type:build/install Build and install issues

Comments

@davideb91
Copy link

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!

@girving girving added the type:build/install Build and install issues label Feb 10, 2017
@andrewharp
Copy link
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
Copy link
Author

davideb91 commented Feb 10, 2017

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
Copy link
Contributor

@davideb91 What does adb logcat say?

@davideb91
Copy link
Author

davideb91 commented Feb 11, 2017

@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
Copy link
Contributor

Is the label file actually in your assets folder?

@davideb91
Copy link
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
Copy link
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
Copy link
Contributor

Great!

@AnSharypov
Copy link

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

@davideb91
Copy link
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
Copy link

@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
Copy link

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
Copy link

SheezaShabbir commented Jul 5, 2018

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
Labels
type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests

7 participants