GithubHelp home page GithubHelp logo

C library for Android about hello_tf_c_api HOT 22 CLOSED

neargye avatar neargye commented on June 12, 2024
C library for Android

from hello_tf_c_api.

Comments (22)

Neargye avatar Neargye commented on June 12, 2024

TFLite is a library more suitable for mobile devices. Maybe you try it for android?
I use TF on macos/win, and TFLite on ios/android.

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Does TFLite use the same API as TF C?
I'm working on a project with a headset that runs Android OS. The SDK of that headset allows me to link to .so libraries. That's why I like to know if there is a similar libtensorflow.so for Android.
If it is convenient for you, could you kindly add TFLite usage to your repo?
It'll help me a lot, and I think other people would also be interested in how to use TFLite in Android.

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

You need use tf in c++? Or in java?

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

In C/C++

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

I try add my example.
For now you can try this http://www.sanj.ai/Android-App-With-Tflite-C++-API/

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Thanks very much. Could you let me know after you add your examples?
Your tutorials are very concise and clear.

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

Yes, I update this issues when adding android example

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Yes, I update this issues when adding android example

Hi. I'm wondering the progress of updating Tensorflow Lite. No rush though.

BTW, your documents (doc/optimizing.md and doc/prepare_models.md) on mobile devices are detailed and very helpful. I appreciate that.

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Yes, I update this issues when adding android example

Hi. I can run TF Lite C++ in Android now, but your tutorials are still welcome.
BTW, are you able to run batch inputs in TF Lite?
For example, a model takes an input-length of 10. I can use Tensorflow C to feed 50 numbers, which runs 5 times of the model with a single function call (which is much faster than manually running the model 5 times).
I see TFLite Interpreter has a function called ResizeInputTensor, which I think is for this purpose. But I got errors when I try to input more numbers. Is there anything that might easily go wrong for beginners?

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

Hi, check this batch example https://github.com/Neargye/hello_tf_c_api/blob/master/src/batch_interface.cpp

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Hi, check this batch example https://github.com/Neargye/hello_tf_c_api/blob/master/src/batch_interface.cpp

It works, but it is for Tensorflow C. Do you have examples for TF Lite?
Thanks.

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

Try something like https://stackoverflow.com/questions/51576944/tensorflow-lite-for-variable-sized-input

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Try something like https://stackoverflow.com/questions/51576944/tensorflow-lite-for-variable-sized-input

I tried that before. However, my program crashes whenever I call

ResizeInputTensor();
AllocateTensors();

even I use the exact dimensions without using batches.
For example, my model takes input of dimensions 1, 100, 9
I tried to run

this->interpreter->ResizeInputTensor(this->interpreter->inputs()[0], {1, 100, 9});
this->interpreter->AllocateTensors();

it crashes. However, if I just call

this->interpreter->AllocateTensors();

then everything works fine. Not sure what goes wrong.

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

I changed Tensorflow Lite version to 2.0, which allows me to run

this->interpreter->ResizeInputTensor(this->interpreter->inputs()[0], {1, 100, 9});
this->interpreter->AllocateTensors();

Basically, nothing is changed because I just call ResizeInputTensor with original/default dimensinos.

However, I cannot change to other dimensions. This is still an open issue here
tensorflow/tensorflow#22377
It seems that Android Tensorflow Lite does not support it.

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

could you please send project example, I will try myself

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

could you please send project example, I will try myself

I attach my sample project below. Thanks.
sample project

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

Hi, I do some test, it seems you are right, Android Tensorflow Lite does not support it.

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Hi, I do some test, it seems you are right, Android Tensorflow Lite does not support it.

Thanks. BTW, do you know if it works in iOS? I'm just curious about that.

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

Hm, I can check tomorrow in iOS.

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

Hm, I can check tomorrow in iOS.

Thank you. Please let me know after you check it.

from hello_tf_c_api.

Neargye avatar Neargye commented on June 12, 2024

I could not do it on iOS.

from hello_tf_c_api.

dtczhl avatar dtczhl commented on June 12, 2024

I could not do it on iOS.

Thanks.

from hello_tf_c_api.

Related Issues (20)

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.