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
Comments
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? |
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. 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 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 ! |
@andrewharp could you comment on the intended behavior before OP embarks on the next experiment? |
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? |
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! |
@alan23273850 |
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?
The text was updated successfully, but these errors were encountered: