dailystudio / ml

ML related stuff
Apache License 2.0
140 stars 48 forks source link

How do you use this repositry for android deployment. Kindly explain a bit. #2

Open Manugoyal123 opened 6 years ago

Manugoyal123 commented 6 years ago

I generated frozen model as per instructions. Now I am wondering how to install this application on android.

Gauravv97 commented 5 years ago

To use this frozen model create assets folder in your project folder where java and res folder reside. Now paste this frozen_inference_graph.pb in this assets folder.

create a string in your java file where you will use tensorflow mobile.

private final static String MODEL_FILE = "file:///android_asset/frozen_inference_graph.pb";

now create TensorFlowInferenceInterface to use this model

public synchronized static boolean initialize(Context context) {      

    sTFInterface=new TensorFlowInferenceInterface(context.getAssets(), MODEL_FILE);
    .
    .
    .
}

flatten your bitmap data, pass it onto the sTFInterface and fetch results.

sTFInterface.feed(INPUT_NAME, mFlatIntValues, 1, h, w, 3 );
sTFInterface.run(new String[] { OUTPUT_NAME }, true);
sTFInterface.fetch(OUTPUT_NAME, mOutputs);

The mOutputs is your Flattened segment mask use it as per your requirement .👍👍

dailystudio has created this awsome project but (No disrespect) my project required the model file to be embedded in the apk itself so i had to use assets.. You can look at the full working code of the above snippet here in my project CameraBlur.