GithubHelp home page GithubHelp logo

template-for-tflite-on-android's Introduction

Template-for-tflite-on-android

This is a template to test the reference speed of tflite model on android.

  • run the notebook to generate tflite model

    import tensorflow as tf
    from tensorflow.keras.applications import MobileNetV2
    
    model = MobileNetV2(weights='imagenet')
    converter = tf.lite.TFLiteConverter.from_keras_model(model)
    tflite_model = converter.convert()
    open("mobilenet.tflite", "wb").write(tflite_model)
  • put tflite model in assets folder

    ".\tfliteDemo\app\src\main\assets"

  • change model name in MainActivity.java

    private static final String MODEL = "mobilenet.tflite"; // model name
  • change the input and output shape in MainActivity.java "ModelRunAsyncTask"

  • you can put tflite.run(in, out) in a loop to test average reference speed

        private class ModelRunAsyncTask extends AsyncTask<Void, Void, Integer> {
            @Override
            protected Integer doInBackground(Void... args) {
    //            if output is an image
    //            int width = bitmap.getWidth();
    //            int height = bitmap.getHeight();
    //            float[][][][] out = new float[1][height][width][3];
                
                int height = 224;  // input shape
                int width = 224;
                float[][]out = new float[1][1000];  // output array
                float[][][][] in = getScaledMatrix(height, width, bitmap);
                long startTimeForReference = SystemClock.uptimeMillis();
                tflite.run(in, out);
                long endTimeForReference = SystemClock.uptimeMillis();
                referenceTime = endTimeForReference - startTimeForReference;
                Log.i(TAG, "Reference Time: " + referenceTime);
    
    //            outputBitmap = getBitmap(height, width, out);
                Message msg = Message.obtain();
                msg.arg1 = 1;
                mHandler.sendMessage(msg);
                return 1;
            }
        }

https://codelabs.developers.google.com/codelabs/recognize-flowers-with-tensorflow-on-android/#0

template-for-tflite-on-android's People

Contributors

leolya avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.