B4A Library TensorFlowLite - an experimental machine/deep learning wrapper

inakigarm

Well-Known Member
Licensed User
Longtime User
Great! Any chance to have an B4J Lib? (It seems it supports Java access to their API https://www.tensorflow.org/install/install_java)
 

moster67

Expert
Licensed User
Longtime User
Great! Any chance to have an B4J Lib? (It seems it supports Java access to their API https://www.tensorflow.org/install/install_java)
Yes, yesterday I started writing a small wrapper for B4J. It works fine. There are some methods I'd like to add before publishing it such as dealing with Images (equivalent to Bitmaps in B4A) in memory. I also want to test it with a model created by me. Once I have this working, I will publish it.
 

microbox

Active Member
Licensed User
Longtime User
Hi moster67...thank you for this lib. I'm new to this (ML) and I would like to create an app to classify leaf if this possible. Any guide that will help me to start is much appreciated.
 

moster67

Expert
Licensed User
Longtime User
Follow the two tutorials mentioned in the first post

You need to set up Python on your computer, better if it is Mac or Linux but it will work with Windows too although you may need to change some things in the parameters you pass on to the training scripts.

You can probably record a video of your objects (leaves) i.e a video for each object. Make sure to record from different angles, in different light conditions etc. Then you can use ffmpeg to extract single photos of each object and then classify them according to the instructions in the tutorial

Then you train your model, trying to find the right resolution of the photos to use. You need to experiment a lot for best results in order to avoid overfitting and underfitting. It takes trial and error to get the best results

Watch tutorials on YouTube, get a book to understand better.

With patience you will get there. Good luck.
 

microbox

Active Member
Licensed User
Longtime User
@moster67
Hi...Thanks for again for the library. The example runs with no problem. I followed the tutorial at code lab. I have a running python and tensorflow. My question is... to test the flower photos on your given demo application. I need to drop existing graph.lite and labels.txt and replace it with the same filename and extension produced in tensorflow-for-poets-2 under android\tflite\app\src\main\assets folder?

I think I'm missing somewhere...it recognise daisy photos only...don't recognise rose and other flowers.

regards,
joe
 
Last edited:

moster67

Expert
Licensed User
Longtime User
Add your graph and labels file to your Asset-folder. I don't remember but I think you can name them whatever you want as long as you use the right extension names (i.e *.lite and *.txt). Then when you initialize the lib, you pass on the names of the files:
B4X:
ten.Initialize("", 224, "yourgraph.lite", "yourlabels.txt")

If you use my demo-app and use different names, make sure to change the code which verifies if a file exists in the asset-folder.
At this point, you should be able to remove any previous files (if present)
 

microbox

Active Member
Licensed User
Longtime User
I think I know what I'm missing...the following code does not execute "tflite_convert --help" this tool is required to convert
retrained_graph.pb to *.lite file. How can install tflite converter? BTW i'm running on mac.

thanks,
Joe
 

moster67

Expert
Licensed User
Longtime User
My library allows user to use their graphs with Android and hence your question is rather off-topic since your problem seems related to setting up the tools needed on your Mac and generating the graphs.

As mentioned earlier, to create the graphs, to do the training avoiding overfitting/underfitting and so on take some time and lots of "trial and error" etc. There are many sources on the internet, such as You Tube tutorials, guides, information on StackOverflow which can help you. That is the way I did it and eventually I got it right

In your case, maybe something such as a dependency was not installed correctly or maybe the input files in the script(s) are not pointing to the correct file locations and so on. Hard to tell for me. You are probably better off asking on StackOverflow giving as much information as possible as to what you have done and perhaps someone can help you out.

I am sorry I cannot be of any further help now, also because I have moved on to other projects which is keeping me really busy and also because it was some time ago I worked on the wrapper and machine learning and I don't remember everything (I am getting old...).
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Hi, All
Is it possible by this lib to identify the objectX among similar object0....object999 that have some image-hashs in a db?
 

moster67

Expert
Licensed User
Longtime User
I guess you mean through image recognition. If yes, then it should be possible but you need to train your model and test it properly.

The easiest way is to film your single objects (from different angles and with different light conditions), then label each video (maybe with your image-hashs) and then use ffmpeg to extract the frames. Using the frames, you can train the model. Once you have generated the model with all your existing objects, you can thereafter add other objects when required, repeating partial steps of the training.

I wrote some hints in this thread what regards tutorials etc. Be prepared it will take some time to get good results with the training and to fine-tune.

Good luck.
 

peacemaker

Expert
Licensed User
Longtime User
to get good results with the training and to fine-tune
Thanks. But anyway what can be the probability of correct recognition an object among the almost same ? Say, cups set with the various printings on them.
 

moster67

Expert
Licensed User
Longtime User
Thanks. But anyway what can be the probability of correct recognition an object among the almost same ? Say, caps set with the various printings on them
As long there is something which distinguishes them apart, I think you can expect good results. I know people who have implemented recognition of flowers. The source (video-frames) and the training (avoiding overfitting/underfitting) are important. Start practicing and testing and see what results you get.
 

peacemaker

Expert
Licensed User
Longtime User
recognition of flowers

Here yes, i can imagine rather noticeable difference in flowers. But if similar Internet-shop's items, with difference just in some part of the same surface...
And if for this kind the probability is < 99%, i guess, such solution won't be interesting to the customer...
But, it seems, unknown result without practical test.
 

moster67

Expert
Licensed User
Longtime User
unknown result without practical test
Yep, you need to test. That is part of the learning curve. Trial and error will give you experience and better understanding if a project is viable or not. In this case, there are no shortcuts. Sorry.
 

rkxo

Active Member
Licensed User
Longtime User
hi, i get error. Any Idea?
 

ZJP

Active Member
Licensed User
Longtime User
Done : Lobe AI is available.


 

SJQ

Member
Licensed User
Longtime User
Unfortunately Lobe Models cause this error:
Internal error: Cannot create interpreter: Op builtin_code out or range: 111. Are you using old TFLite binary with newer model?Registration failed.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…