-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Unable to build Android Example App using Bazel on Windows #6385
Comments
@petewarden, you mentioned you have had experience with android builds on windows. |
Ok, after trying to build the Bazel example Android project on Linux, and reverse engineering the .apk package, it looks like it depends only on a single .so native TensorFlow Android library, called libtensorflow_demo.so. Currently in order to build this simple example on Windows, I needed to:
I think that it could really help if there was an example Android Studio project for windows which does not use Bazel at all. Instead let's put the mentioned above pre-compiled TensorFlow library available for download (for all possible Android architectures - arm64-v8a, armeabi, armeabi-v7a ,x86_64) ,together with a simple tutorial. Obviously, it will not be as flexible as the ability to re-build TensorFlow, but for 99% of users it will suffice to update the pre-built libraries once in a while. |
Unfortunately Bazel doesn't support Android on Windows yet. However we do have cmake support in tensorflow/contrib/android/cmake that should let you build the library necessary for simple Android inference on Windows (this excludes some native code created specifically for the demo). Full demo support should be coming soon, possibly including pre-built libs. As a sort-of-hacky alternative you can grab the APK built by Jenkins here, and unzip it to grab libtensorflow_demo.so to manually place into your project. |
@AndreyRub Please see http://ci.tensorflow.org/view/Nightly/job/nightly-android/ for a full selection of prebuilt Android TF libs, which has just come online. You can either download libtensorflow_inference.so for something that can be dropped into a standalone app, or grab In either case you will need libandroid_tensorflow_inference_java.jar as well for the Java counterpart. |
@andrewharp or @AndreyRub Could you please provide some steps for such goal:
I am really stuck with it. Thank you. |
@bulatyauheni Bazel does not support Android on Windows yet. You might try the cmake build, but easiest thing to do if you just want to plug something into your Android Studio project is to grab the pre-built libraries referenced above. |
@andrewharp Hey Andrew I am trying to build tensorflow/examples/android on windows 7 using Android Studio. Is it possible or not ? |
@Anmolk22 I'll try to help you. Bazel does not work properly on Windows, so for building project you should use prebuilded libs.
|
The native libs necessary for the demo can now be built with make via Android Studio, completely removing the need for Bazel on Linux and OS X system. Set However, it seems some extra changes will still be required to get this to get the make builds to work on Windows, so reopening to track. |
Ok, I've got something sort of working. It needs some more tweaking, and I would recommend sticking with the prebuilts as described by @bulatyauheni above, but if you're feeling adventurous here's how you can build the Android TF libraries on Windows 10. First, install Bash for Windows as described here: https://msdn.microsoft.com/en-us/commandline/wsl/about Once that's done, start bash and run the following, adjusting directories appropriately:
Now create a file named "makefile_helper.bat" in tensorflow/ and add the following to it:
(The '-T' will prevent it from redownloading and compiling protobuf every time) Then update build.gradle buildNativeMade to the following:
Now, if you set This should work similarly for bazel on Windows, if you wish to install that under bash instead. I'd prefer not to check in a separate helper script, so if anybody has luck getting the command to run inline in the Exec task itself please let me know. |
@bulatyauheni @AndreyRub
Any help would be very useful! |
@ramarajan09 |
@bulatyauheni I tried to remove that task, however it throws multiple error in this task Could you share the build file you used |
@ramarajan09 |
@vyse8 What are the contents of the apk as seen with unzip -v? I'm not sure why you'd have an aar in jnilibs unless you put it there yourself (and you probably shouldn't). All you should need to do is change cpuType to "armeabi-v7a". The code is already set up to composite the directory name correctly for you. |
@andrewharp From what I can tell it looks like anything that is placed in my libs folder gets moved to jnilibs. I believe this occurs because of the following lines in build.gradle manifest.srcFile 'AndroidManifest.xml' I went ahead and changed the cputype back to armeabi-v7a but still getting the libtensorflow_demo.so couldn't be found error. I did find some additional info by using the Analyze apk feature in Android Studio. It looks like at the root there is a lib folder, and within that folder are the types (x86, x86_64, arm64_v8a, armeabi-v7a). However, within those folders, the only file listed in each one is libtensorflow_inference.so. This would explain why it is having difficulty finding the libtensorflow_demo.so. Should this file be located in the same directory ideally? I don't see it anywhere within the apk. Also, if I were wanting to build the sample Hello World tensorflow example within Android, would I only need the latest inference file? Thank you so much for all of this help btw. |
@vyse8 In your situation I'd suggest just ignoring that the AAR even exists and following only the instructions in the original workaround. It's hard to tell what's going on if we don't even know what's in the APK (again, you can find out with unzip -v). |
@andrewharp my apologies, I was unfamiliar with unzip so I equated it to Analyze APK, I see now that it provides a better output. Here it is: Length Method Size Cmpr Date Time CRC-32 Name
10492 Defl:N 5554 47% 1980-00-00 00:00 bdb9b97a assets/imagenet_comp_graph_label_strings.txt 131783009 89887795 32% 50 files |
Ok, if you really want to use the AAR try a directory different than libs/ for it (it could be "foobarbaz" as long as you update the dirs directive). "libs/" may be conflicting with where gradle expects to find the native libs. You might also try the this option for manually placing the prebuilts in the right place. We'll have cmake working for libtensorflow_demo.so possibly next week, so really this is not worth spending too much time on. |
@andrewharp thanks for your assistance. Now that I scroll up I realize I hit the same issue that ramarajan09 had 22 days ago prior to the AAR. It looks like we both got the same exact error message so I'm not sure what is causing that for us. From further analysis of the apk it looks like dragging it to an arbitrary created libs folder doesn't signal to the APK to include it in the build. Do you know how these libs can be included as I think that would solve both of our issues? One question that I think I might be stumbling on is the libs path. What is the recommendation as mine is currently set to: def demoLibPath = '../libs/armeabi-v7a/libtensorflow_demo.so' The full path in reality is C:\Users\mattv\OneDrive\Documents\GitHub\tensorflow\tensorflow\examples\android\libs\armeabi-v7a. Would this be causing the issue? |
@vyse8 To clarify: The AAR, if you use it, needs to go in an arbitrary folder that matches "aardir" in:
The .so files, if placed manually, need to be put in the arbitrary folder that matches the "libs" in: The only restriction is possibly that these two dirs should be different -- my original instruction to place the AAR in libs/ may have been incorrect (I actually tested using a different directory). Note that when AS shows you the project outline visually, I think it shows up as "jniLibs", though the actual folder on your HD is "libs". |
I used the prebuilt libraries (copied the folder
|
…ck if native implementation is not found. This means that compiling libtensorflow_demo.so will only be strictly necessary for the Detection example (which uses native object tracking). A followup change will add graceful degradation in that case too. Java conversion may be slower depending on the device, but should still be acceptable for demo purposes as the majority of the compute time will still be spent on TF inference passes. Note that this has no effect on the necessity of libtensorflow_inference.so, which provides the actual TF support. However libtensorflow_inference.so may be added to applications via the prebuilt AAR, so no native compilation is necessary. Partially addresses tensorflow#6385 Change: 155121431
…ve ObjectTracker support is found. If libtensorflow_demo.so is not found in the APK, rendered boxes will simply be stationary and will be replaced whenever new results come in. Partially addresses tensorflow#6385 Change: 155159326
Another update: libtensorflow_demo.so is now (as soon as the above commits get pushed to master) an optional library. If not present, YUV->RGB color conversion will be performed in Java (possibly slower), and object tracking will be disabled in the TF Detect demo, but otherwise things will work as usual. This means the demo can be built on Windows with just the prebuilt tensorflow.aar dropped into your project folder. We're in the process of uploading this to jcenter, at which point it will only take a couple of lines of Gradle config to add a TF dep to Android projects. Full cmake support for building TF is also still on the roadmap (no timeline for this yet though). |
The AAR build of TF is now live! This is labeled 1.2.0 preview, but note that this is merely to indicate it comes between 1.1.0 and 1.2.0 (the 1.2.0 release branch has not even been cut yet). We'll be updating it on every point release going forward. You can enable it in your Android app by adding the following to build.gradle:
For the official TF demo, you'll also want to remove the following to prevent redundant Java classes from being included:
And remove the reference to the locally-built inference lib as well: If using an arm64 device, change cpuType from armeabi-v7a to arm64-v8 (since you'll need libtensorflow_demo.so to be built at the highest architecture target your device can use that the AAR provides libtensorflow_inference.so at). If using bazel to build, change the following in buildNativeBazel: and if using make, change the following in buildNativeMake: Once fd69bb2 and efa08d8 are pushed to master (which will make libtensorflow_demo.so an optional lib), you could also just remove the native lib dependencies altogether. We'll be cleaning this up to make it easier to switch soon, and also add a cmake build for libtensorflow_demo.so |
Hi @andrewharp Just tried to follow some of the advice in here to get this running on Windows. I've found that by far the easiest method was to just download the nightly binaries and stick them in. I tried to use your above method to use the aar but I got an error saying that the compile method was not available. Seemed to suggest it was a gradle issue. Either way I couldn't fix and resorted to sticking the prebuilts in. Not sure if you've come across this? On another note, this thread has lots of good information and is more detailed than the documentation. Are there plans to get the documentation up to spec to contain all this information? It's slightly unclear atm, especially regarding Windows. I did notice that you said some progress was being made. Thanks for your help. |
@jubjamie Can you paste the exact error message please? Haven't seen that one before. The README.md files have recently been updated with AAR instructions, and I'm working on a detailed getting started guide that will cover all of the approaches to building and integrating TensorFlow into apps. |
@andrewharp I've got around the error so not able to get it up again I don't think. It seems to be a common error within android so i've put a very similar message below. Most solutions appear to suggest removing the compile line however that's for those specific stack overflow situations. Here it's not so simple.
In my scenario I obviously had gradle installed etc. I noticed that in the latest release there is another compile call at the very end of build.gradle which it didn't pick up on (but I wonder if that is because it didn't get that far?). This was using android on Windows 10. I was about to open another issue regarding performance of the android app using custom tensorflow for poets models (takes 5 times as long) but not sure it's really a bug or a stack overflow question. Can I email you? Otherwise I can open a stack overflow and paste the link here? @petewarden here too perhaps? |
@jubjamie Ok -- I assume this sort of thing can be cleared up in Android Studio by just clicking to install/upgrade whatever Gradle-related thing it asks you to? Or were you building from the command line? Re Inception: the performance of v3 (from the TF for Poets guide) is known to be slower than v1 (aka 5h, bundled with the demo). It's a much larger model so some difference is expected. Speeding it up is more of a Stack Overflow topic, but if you're interested you might try seeing what ops are taking up the most time on your device with tensorflow/tools/benchmark:benchmark_model. |
As a note on performance, I've recently updated the TensorFlow for Poets script with the option to save out MobileNet models, which can be a lot smaller and faster than the default Inception v3, at the cost of some accuracy: It looks like the original issue is fixed, or at least obsolete now though? I'm closing this for the moment, please reopen with more information if that's incorrect. |
The link referring to the AAR build is now giving a 404. Has the link for this windows build method now changed? |
So still no Windows support after a year when this issue was first brought up? Just tried to build the demo. org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':buildNativeBazel'. |
there still no bazel support on windows, you can use cmake, but still its performance still no guarantee though |
Hey guys, I am trying to include some experimental operators located in the contrib folders(tensor_forest) to a tensorflow build so that I can load a tensorflow model in my xamarin.android project using these operators without an error that states that the operators are not recognized. In order to do this I thought I started with trying to build tensorflow android throught this command: But I keep getting these kinds of errors Is there still no bazel support for windows? |
Anmolk22 hi can you please tell how you should build libtensorflow_infrence.so file |
What related GitHub issues or StackOverflow threads have you found by searching the web for your problem?
#6101
#6383
http://stackoverflow.com/questions/40978859/creating-simple-android-app-using-android-studio-and-tensorflow
Environment info
Operating System: Windows
Installed version of CUDA and cuDNN:
(please attach the output of
ls -l /path/to/cuda/lib/libcud*
):Cuda 8.0
cuDNN 5.0
If installed from source, provide
The commit hash (
git rev-parse HEAD
)I downloaded the latest ZIP on 18 Dec 2016. Sorry, I have no idea how to get the version.
The output of
bazel version
Build label: 0.4.2
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Dec 7 18:47:13 2016 (1481136433)
Build timestamp: 1481136433
Build timestamp as int: 1481136433
My goal is to build an Android App which loads pre-trained TensorFlow model and runs it on an Android device. I am working on Android Studio on Windows. Unfortunately using Android Studio on Linux is currently not an option.
Following previous advice from this forum, I am trying to build an Android example using Bazel on Windows.
I've successfully installed Bazel using Chocolatey.
Following the build instructions, I changed the SDK and NDK paths in WORKSPACE file and ran:
bazel build //tensorflow/examples/android:tensorflow_demo
So far I did the following to fix errors:
But I am stuck again. I am getting the following error which I have no idea how to fix:
The text was updated successfully, but these errors were encountered: