Skip to content

Commit

Permalink
Get model from API for android
Browse files Browse the repository at this point in the history
  • Loading branch information
nsipplswezey committed Jan 9, 2018
1 parent 4f790cc commit 30c01f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Expand Up @@ -57,7 +57,7 @@ static void initDeepBelief() {
String predictorFileName = "VoltAGE_2_predictor.txt";
String predictorFile = dataDir + "/" + predictorFileName;
copyAsset(am, predictorFileName, predictorFile);
predictorHandle = JPCNNLibrary.INSTANCE.jpcnn_load_predictor(predictorFile);
//setPredictor(predictorFile);

Bitmap lenaBitmap = getBitmapFromAsset(am,"lena.png");

Expand All @@ -68,6 +68,10 @@ static void initDeepBelief() {

}

public static void setPredictor(String predictorFilePath){
predictorHandle = JPCNNLibrary.INSTANCE.jpcnn_load_predictor(predictorFilePath);
}

private static boolean copyAsset(AssetManager assetManager,
String fromAssetPath, String toPath) {
InputStream in = null;
Expand Down
Expand Up @@ -506,6 +506,33 @@ public void orientationEvent() {
@ReactMethod
public void setCNNModel(final String model) {
Log.d(TAG, "setCNNModel called");

//write string to file
String predictorFileName = "VoltAGE_predictor_from_api.txt";
FileOutputStream outputStream;

try {
outputStream = DeepBelief.ctx.openFileOutput(predictorFileName, DeepBelief.ctx.MODE_PRIVATE);
outputStream.write(model.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}

//get file path
String dataDir = DeepBelief.ctx.getFilesDir().getAbsolutePath();
Log.d(TAG, dataDir);
String predictorFilePath = dataDir + "/" + predictorFileName;
Log.d(TAG, predictorFilePath);

//if file exists, DeepBelief.setPredictor(predictorFile);
File file = new File(predictorFilePath);
if(file.exists()){
Log.d(TAG, "File exists. Setting predictor");
DeepBelief.setPredictor(predictorFilePath);

}

}

private void captureWithOrientation(final ReadableMap options, final Promise promise, int deviceOrientation) {
Expand Down

0 comments on commit 30c01f7

Please sign in to comment.