androidpythontensorflowlinear-regressionnightly-build

Tensorflow in android: Linear regression


I have completed training a simple linear regression model on jupyter notebook using tensorflow, and I am able to save and restore the saved variables like so:

Grab Data

Now I'm trying to use the model on an android application.

Following the tutorial here, I am able to get to the stage where i import the tensorflow library like so:

Android JNILibs

Now I'm at the point where I want to give the model an input data and get a output value.(Refer to application flow below) However, they are using a .pb file(no clue what this is) in their application. In the 4 files:

Saved File

that i got from saving my model, i do not have a .pb file which left me dumbfounded.

What the application does: Predicts the SoC with a pre-trained tensorflow model using user's input value of height. Whereby, the linear regression equation is used: y = Wx + b

y - SoC

W - weight

x - height

b - bias

All variables are float values.

Android application flow:

  1. User inputs height value in textbox, and presses "Predict" button.

  2. Application uses the weight, bias & height values of the saved model to predict SoC.

  3. Application displays predicted SoC in textview.

So my question is: how do I import and use my model in Android application using android studios 2.3.1?

Here are my ipynb and csv data files.


Solution

  • I may have misunderstood the question but:

    Given that the model is pre-trained, the weight and bias are not going to change, you can simply use the W and b values calculated in the Jupyter notebook and hard code them in a simple expression

    <soc> = -56.0719*<height> + 98.3029
    

    there is no need to import a tensorflow model for this.

    UPDATE To ensure the question is answered, the *.pb file comes from freezing the checkpoint file with the graph - refer to the second code panel in the linked tutorial for how to do this.

    In terms of what freezing is refer here