B4A Library TensorFlowLite - an experimental machine/deep learning wrapper

Discussion in 'Additional libraries, classes and official updates' started by moster67, Aug 22, 2018.

  1. inakigarm

    inakigarm Well-Known Member Licensed 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)
  2. moster67

    moster67 Expert Licensed User

    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.
    inakigarm and JordiCP like this.
  3. moster67

    moster67 Expert Licensed User

    DonManfred likes this.
  4. microbox

    microbox Active Member Licensed 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.
  5. moster67

    moster67 Expert Licensed 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, inakigarm and DonManfred like this.
  6. microbox

    microbox Active Member Licensed User

    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.

    Last edited: Nov 28, 2018
  7. moster67

    moster67 Expert Licensed 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:
    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)
  8. microbox

    microbox Active Member Licensed 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.

  9. moster67

    moster67 Expert Licensed 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: Nov 29, 2018
    microbox likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice