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

    @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: 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:
    Code:
    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)
     
  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.

    thanks,
    Joe
     
  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.
  10. peacemaker

    peacemaker Well-Known Member Licensed 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?
     
  11. moster67

    moster67 Expert Licensed 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.
     
    JordiCP, peacemaker and Erel like this.
  12. peacemaker

    peacemaker Well-Known Member Licensed User

    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.
     
  13. moster67

    moster67 Expert Licensed User

    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 likes this.
  14. peacemaker

    peacemaker Well-Known Member Licensed User

    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.
     
  15. moster67

    moster67 Expert Licensed User

    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.
     
    peacemaker likes this.
  16. rkxo

    rkxo Member Licensed User

    hi, i get error. Any Idea?
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Make sure to use Java 8+ and a recent version of B4A.
     
  18. rkxo

    rkxo Member Licensed User

    thanks, erel
     
Loading...
  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