0

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.

Tix
  • 449
  • 1
  • 8
  • 27
  • The information about freezing the model to create a pb graph is in the tutorial that you linked in the question... In the first part of the tutorial it explains exactly how to freeze a graph and checkpoints into a model. – JCooke Jul 04 '17 at 09:26

1 Answers1

2

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

pypypy
  • 1,075
  • 8
  • 18
  • This is one of those answers that answers the question but doesn't! I often wonder why so many people try to put simple linear regression in their apps when it's just a solved equation! – JCooke Jul 04 '17 at 09:24
  • Thanks for the reply, but my project is part of a school module where i have to learn how to get data and input data into tensorflow models on android, as future project requires this knowledge. – Tix Jul 04 '17 at 09:26
  • pypypy has updated their answer for you now. The answer to your question was in the tutorial all along! Perhaps you didn't read all of it? If you didn't read https://omid.al/posts/2017-02-20-Tutorial-Build-Your-First-Tensorflow-Android-App.html , another tutorial linked in the one you posted, that might also be good reading for your school project. Good luck. – JCooke Jul 04 '17 at 09:35