Skip to content
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

Should *.pb.h files be generated in cross-compile cases? #3544

Closed
alan23273850 opened this issue Jul 28, 2016 · 6 comments
Closed

Should *.pb.h files be generated in cross-compile cases? #3544

alan23273850 opened this issue Jul 28, 2016 · 6 comments
Assignees

Comments

@alan23273850
Copy link

A few days ago, I have tried to import the tensorflow project directly into Android Studio on Windows and use Gradle to build the project. Header files with suffix ".pb.h" are not generated. Google says bazel should be used to build the project. Now I use bazel on Linux to build it again with CPU=arm64-v8a using the following command

bazel build //tensorflow/examples/android:tensorflow_native_libs --crosstool_top=//external:android/crosstool --cpu=$CPU --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

as in the issue #3444 .

However header files with suffix ".pb.h" are still not generated. Android Studio cannot find the include file and hence the build procedure cannot be continued. Is there any method to use tensorflow C++ library in Android Studio?

@michaelisard
Copy link

Did the bazel build appear to succeed? For completeness, would you build CPU=armabi-v7a as in #3444 and see if the headers are generated for that target?

@michaelisard michaelisard added the stat:awaiting response Status - Awaiting response from author label Jul 28, 2016
@alan23273850
Copy link
Author

alan23273850 commented Jul 28, 2016

For both cases(arm64-v8a and armeabi-v7a), there were only warnings like the following:

(1) WARNING: /home/alan/.cache/bazel/_bazel_alan/16525490ccae1ec04acb6f1b1a5f7367/external/protobuf/WORKSPACE:1: Workspace name in /home/alan/.cache/bazel/_bazel_alan/16525490ccae1ec04acb6f1b1a5f7367/external/protobuf/WORKSPACE (@main) does not match the name given in the repository's definition (@protobuf); this will cause a build error in future versions.
(2) WARNING: /home/alan/Desktop/Tensorflow_On_Android_Playground/tensorflow/tensorflow/core/BUILD:640:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_beam_search.h' directly. You should either move the file to this package or depend on an appropriate rule there.

without any error. I think bazel build succeeded. In addition, libtensorflow_demo.so were generated successfully.

Unfortunately, even if CPU=armeabi-v7a, the *.pb.h headers are still not generated. (For example, I have only tensorflow/core/framework/graph.proto instead of tensorflow/core/framework/graph.pb.h)

I wonder the bazel generates *.pb.h only when it is used to generate the whole apk using the following command

bazel build //tensorflow/examples/android:tensorflow_demo

on the official website
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android
, but I cannot try it now because I have no sdk on my ubuntu. Should I install sdk on my ubuntu and try the whole apk version again? Because my whole project is on Windows Android Studio, I hope I can use tensorflow on Windows.

Umm.. After all I think I should guarantee the answer to the following question is YES first, or I don't have to build the "whole" headers on Linux.

If libtensorflow_demo.so and the *.pb.h headers are generated successfully on "Linux" eventually, can I just migrate libtensorflow_demo.so to Windows as a jni library and the whole tensorflow project as jni include header files and guarantee that tensorflow functions can work successfully on "Windows?" (i.e. regardless of OS difference)

Thanks for your help !

@michaelisard michaelisard removed the stat:awaiting response Status - Awaiting response from author label Jul 28, 2016
@michaelisard
Copy link

@andrewharp could you comment on the intended behavior before OP embarks on the next experiment?

@andrewharp
Copy link
Contributor

The generated header files should not be necessary unless you are planning on modifying the Tensorflow C++ code in Android Studio. Merely copying the built libtensorflow_demo.so to the appropriate libs/ directory is sufficient, and then you can build it as a regular Android application in Android Studio.

You also don't need the SDK on your Ubuntu machine unless you desire to build the entire project with Bazel.

How are you attempting to make Gradle build the project, such that it is even looking for these pb.h files?

@michaelisard michaelisard added the stat:awaiting response Status - Awaiting response from author label Jul 28, 2016
@alan23273850
Copy link
Author

I have thought originally that .so libraries must be accompanied with source codes to satisfy JNI structure. Thanks for correcting my thoughts!

In fact, I have written some codes to preprocess some captcha last summer for my practice(low recognition rate). On this summer vacation, I plan to migrate it from my Ubuntu virtual machine to android cell phone for convenience. Thanks to the project https://github.com/niektemme/tensorflow-mnist-predict , I can use the classifier model to recognize digits. It includes two kinds of python script. Create_model.py is used to generate model (*.ckpt) and predict.py is used to predict the value from digit image using the model built by create_model.py.

My final final purpose is to execute predict_2.py on my android. It includes tensorflow module. I originally want to rewrite the python script in C++ language and migrate the generated .so library on my android studio project. Should I still need to move the whole source code to Windows Android Studio? The answer is NO according to your answer, am I right? Additionally, if I want to write my own C++ codes with tensorflow, should the bazel build file also be modified?

Thank you again for solving my problem!

@michaelisard michaelisard removed the stat:awaiting response Status - Awaiting response from author label Jul 28, 2016
@andrewharp
Copy link
Contributor

@alan23273850
If you don't need to modify the native C++ code, then no you can just copy the built .so file into your Android studio project as described. However, if you plan to modify them, you'll need to rebuild, which at this point will be hard to do in Windows due to the lack of Bazel support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants