Giter Site home page Giter Site logo

amitshekhariitbhu / androidtensorflowmachinelearningexample Goto Github PK

View Code? Open in Web Editor NEW
1.4K 82.0 428.0 53.13 MB

Android TensorFlow MachineLearning Example (Building TensorFlow for Android)

Home Page: https://amitshekhar.me

License: Apache License 2.0

Java 100.00%
tensorflow tensorflow-tutorials tensorflow-android machine-learning machine-learning-android tensorflow-models tensorflow-examples deep-learning deep-neural-networks deeplearning

androidtensorflowmachinelearningexample's Introduction

About me

Hi, I am Amit Shekhar, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

Learn from my blogs: amitshekhar.me/blog

Learn from my videos: youtube.com/@amitshekhar

Get High Paying Tech Job: amitshekhar.me

You can connect with me on:

androidtensorflowmachinelearningexample's People

Contributors

amitshekhariitbhu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidtensorflowmachinelearningexample's Issues

Using Inception V3 instead of 5h?

The app crashes after a few seconds of startup when used Inception V3. The current one is 5h. I've set Image_Size=299, Image_Mean=128, inputname to "mul" and output name to "final_result".

How to use placeholder

I want to use tensorflow model in android.But I don't know how to use placeholder.Can you help me?

App crashes

The App crashes when I am trying to run it using my own graph file and labels file.
I tweaked the code in mainActivity.java accordingly.

Is the app hardcoded to run using only your graph and label files?

No operation named [ipnode] in the Graph

I have completed training the dataset using TensorFlow and I am freezing the model. A protobuffer file(.pb) has been created and I am providing the same to Android Studio.

After running the app I am getting the following error:"No operation named [ipnode] in the Graph".

TechStack:
Spyder(Python 3.7)
Tensorflow version-1.13.1
Android Studio version- 3.4
compile SDKVersion is 28 and TargetVersion is 28 in build.grade (Module:app)

.so file is not available

From the medium blog:
Now we have both jar and .so file. I have already built both .so file and jar, you can directly use from the below project.

I did not find the .so file.

cant build .so file

I followed the steps to your blog but I get an error about c/c++ files in the cpp folder(created by itself). I dont know how you built the .so file. I have built the jar file fine.

Can I make a request

I need function like this:
I will enter a set of images and when I Detect Object some thing,
this program can match between some thing to images
is that possible?

run app is error

Process: com.mindorks.tensorflowexample, PID: 517
java.lang.RuntimeException: Error initializing TensorFlow!
at com.mindorks.tensorflowexample.MainActivity$5.run(MainActivity.java:158)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: Native TF methods not found; check that the correct native libraries are present and loaded.
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.(TensorFlowInferenceInterface.java:57)
at com.mindorks.tensorflowexample.TensorFlowImageClassifier.create(TensorFlowImageClassifier.java:108)
at com.mindorks.tensorflowexample.MainActivity$5.run(MainActivity.java:147)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 

error creating so file

i have followed the procedure you described to create the so file.
i modified the workspace file and added the last 2 parts so thew workspace became as follows

workspace(name = "org_tensorflow")

http_archive(
name = "io_bazel_rules_closure",
sha256 = "a38539c5b5c358548e75b44141b4ab637bba7c4dc02b46b1f62a96d6433f56ae",
strip_prefix = "rules_closure-dbb96841cc0a5fb2664c37822803b06dab20c7d1",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz", # 2018-04-13
],
)

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")

closure_repositories()

We must check the bazel version before trying to parse any other BUILD

files, in case the parsing of those build files depends on the bazel

version we require here.

load("//tensorflow:version_check.bzl", "check_bazel_version_at_least")
check_bazel_version_at_least("0.10.0")

load("//tensorflow:workspace.bzl", "tf_workspace")

load("//third_party/android:android_configure.bzl", "android_configure")
android_configure(name="local_config_android")
load("@local_config_android//:android.bzl", "android_workspace")
android_workspace()

Please add all new TensorFlow dependencies in workspace.bzl.

tf_workspace()

new_http_archive(
name = "inception_v1",
build_file = "models.BUILD",
sha256 = "7efe12a8363f09bc24d7b7a450304a15655a57a7751929b2c1593a71183bb105",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/inception_v1.zip",
"http://download.tensorflow.org/models/inception_v1.zip",
],
)

new_http_archive(
name = "mobile_ssd",
build_file = "models.BUILD",
sha256 = "bddd81ea5c80a97adfac1c9f770e6f55cbafd7cce4d3bbe15fbeb041e6b8f3e8",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_android_export.zip",
"http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_android_export.zip",
],
)

new_http_archive(
name = "mobile_multibox",
build_file = "models.BUILD",
sha256 = "859edcddf84dddb974c36c36cfc1f74555148e9c9213dedacf1d6b613ad52b96",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/mobile_multibox_v1a.zip",
"http://download.tensorflow.org/models/mobile_multibox_v1a.zip",
],
)

new_http_archive(
name = "stylize",
build_file = "models.BUILD",
sha256 = "3d374a730aef330424a356a8d4f04d8a54277c425e274ecb7d9c83aa912c6bfa",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/stylize_v1.zip",
"http://download.tensorflow.org/models/stylize_v1.zip",
],
)

new_http_archive(
name = "speech_commands",
build_file = "models.BUILD",
sha256 = "c3ec4fea3158eb111f1d932336351edfe8bd515bb6e87aad4f25dbad0a600d0c",
urls = [
"http://storage.googleapis.com/download.tensorflow.org/models/speech_commands_v0.01.zip",
"http://download.tensorflow.org/models/speech_commands_v0.01.zip",
],
)

android_sdk_repository(
name = "androidsdk",
api_level = 23,
build_tools_version = "25.0.1",
# Replace with path to Android SDK on your system
path = "/opt/Android/Sdk/",
)
android_ndk_repository(
name="androidndk",
path="/home/user/Desktop/android-ndk-r13b/",
api_level=14)

when i ran the bazel command bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a i get the following error:

ERROR: /home/user/tensorflow/tensorflow/core/BUILD:2306:1: C++ compilation of rule '//tensorflow/core:protos_all_proto_cc_impl' failed (Exit 1)
In file included from bazel-out/armeabi-v7a-opt/genfiles/tensorflow/core/framework/function.pb.cc:4:
In file included from bazel-out/armeabi-v7a-opt/genfiles/tensorflow/core/framework/function.pb.h:9:
In file included from external/protobuf_archive/src/google/protobuf/stubs/common.h:52:
In file included from external/protobuf_archive/src/google/protobuf/stubs/mutex.h:33:
In file included from external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/mutex:35:
external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the
^
In file included from bazel-out/armeabi-v7a-opt/genfiles/tensorflow/core/framework/function.pb.cc:4:
In file included from bazel-out/armeabi-v7a-opt/genfiles/tensorflow/core/framework/function.pb.h:9:
In file included from external/protobuf_archive/src/google/protobuf/stubs/common.h:52:
external/protobuf_archive/src/google/protobuf/stubs/mutex.h:58:8: error: no type named 'mutex' in namespace 'std'
std::mutex mu_;

In file included from bazel-out/armeabi-v7a-opt/genfiles/tensorflow/core/framework/function.pb.cc:4:
In file included from bazel-out/armeabi-v7a-opt/genfiles/tensorflow/core/framework/function.pb.h:9:
In file included from external/protobuf_archive/src/google/protobuf/stubs/common.h:53:
external/protobuf_archive/src/google/protobuf/stubs/callback.h:346:25: error: no type named 'remove_reference' in namespace 'std'
typedef typename std::remove_reference<T>::type base_type;
        ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:346:41: error: expected member name or ';' after declaration specifiers
typedef typename std::remove_reference<T>::type base_type;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
external/protobuf_archive/src/google/protobuf/stubs/callback.h:347:17: error: unknown type name 'base_type'
typedef const base_type& type;
              ^
external/protobuf_archive/src/google/protobuf/stubs/callback.h:401:17: error: no type named 'remove_reference' in namespace 'std'
typename std::remove_reference<P1>::type p1_;
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:401:33: error: expected member name or ';' after declaration specifiers
typename std::remove_reference<P1>::type p1_;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
external/protobuf_archive/src/google/protobuf/stubs/callback.h:402:17: error: no type named 'remove_reference' in namespace 'std'
typename std::remove_reference<P2>::type p2_;
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:402:33: error: expected member name or ';' after declaration specifiers
typename std::remove_reference<P2>::type p2_;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
external/protobuf_archive/src/google/protobuf/stubs/callback.h:403:17: error: no type named 'remove_reference' in namespace 'std'
typename std::remove_reference<P3>::type p3_;
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:403:33: error: expected member name or ';' after declaration specifiers
typename std::remove_reference<P3>::type p3_;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
external/protobuf_archive/src/google/protobuf/stubs/callback.h:404:17: error: no type named 'remove_reference' in namespace 'std'
typename std::remove_reference<P4>::type p4_;
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:404:33: error: expected member name or ';' after declaration specifiers
typename std::remove_reference<P4>::type p4_;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
external/protobuf_archive/src/google/protobuf/stubs/callback.h:405:17: error: no type named 'remove_reference' in namespace 'std'
typename std::remove_reference<P5>::type p5_;
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:405:33: error: expected member name or ';' after declaration specifiers
typename std::remove_reference<P5>::type p5_;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
external/protobuf_archive/src/google/protobuf/stubs/callback.h:383:9: error: member initializer 'p1_' does not name a non-static data member or base class
      p1_(p1),
      ^~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:384:9: error: member initializer 'p2_' does not name a non-static data member or base class
      p2_(p2),
      ^~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:385:9: error: member initializer 'p3_' does not name a non-static data member or base class
      p3_(p3),
      ^~~~~~~
external/protobuf_archive/src/google/protobuf/stubs/callback.h:386:9: error: member initializer 'p4_' does not name a non-static data member or base class
      p4_(p4),
      ^~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Target //tensorflow/contrib/android:libtensorflow_inference.so failed to build
Use --verbose_failures to see the command lines of failed build steps.



how to solve this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.