diff --git a/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/MainActivity.java b/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/MainActivity.java index 6eaa36f9506..5eb88a09caa 100644 --- a/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/MainActivity.java +++ b/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/MainActivity.java @@ -286,7 +286,7 @@ public class MainActivity extends AppCompatActivity implements OnBackgroundImage progressBar.setVisibility(View.VISIBLE); new Thread(() -> { isRunningModel = true; - modelTrackingResult = trackingMobile.execut(originBitmap); + modelTrackingResult = trackingMobile.execute(originBitmap); if (modelTrackingResult != null) { isRunningModel = false; lastOriginBitmap = originBitmap; diff --git a/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java b/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java index e892381c8e0..50fe28635f9 100644 --- a/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java +++ b/model_zoo/official/lite/image_segmentation/app/src/main/java/com/mindspore/imagesegmentation/help/TrackingMobile.java @@ -84,19 +84,19 @@ public class TrackingMobile { } msConfig.free(); - // Complile graph. + // Complie graph. if (!session.compileGraph(model)) { Log.e(TAG, "Compile graph failed"); model.freeBuffer(); return; } - // Note: when use model.freeBuffer(), the model can not be complile graph again. + // Note: when use model.freeBuffer(), the model can not be complie graph again. model.freeBuffer(); } - public ModelTrackingResult execut(Bitmap bitmap) { + public ModelTrackingResult execute(Bitmap bitmap) { // Set input tensor values. List inputs = session.getInputs(); if (inputs.size() != 1) { @@ -135,8 +135,8 @@ public class TrackingMobile { int batch = output.getShape()[0]; int channel = output.getShape()[1]; int weight = output.getShape()[2]; - int hight = output.getShape()[3]; - int plane = weight * hight; + int height = output.getShape()[3]; + int plane = weight * height; for (int n = 0; n < batch; n++) { for (int c = 0; c < channel; c++) { diff --git a/model_zoo/official/lite/posenet/README.en.md b/model_zoo/official/lite/posenet/README.en.md index a625e71a0e9..01cea3c6752 100644 --- a/model_zoo/official/lite/posenet/README.en.md +++ b/model_zoo/official/lite/posenet/README.en.md @@ -187,14 +187,14 @@ The inference code process of bone detection demo is as follows. For details abo - Load the model file and build a computational graph for inference. ```java - // Complile graph. + // Compile graph. if (!session.compileGraph(model)) { Log.e("MS_LITE", "Compile graph failed"); model.freeBuffer(); return false; } - // Note: when use model.freeBuffer(), the model can not be complile graph again. + // Note: when use model.freeBuffer(), the model can not be compile graph again. model.freeBuffer(); ``` diff --git a/model_zoo/official/lite/posenet/README.md b/model_zoo/official/lite/posenet/README.md index 17a07ded239..ce7c412fe7c 100644 --- a/model_zoo/official/lite/posenet/README.md +++ b/model_zoo/official/lite/posenet/README.md @@ -190,14 +190,14 @@ - 加载模型文件并构建用于推理的计算图 ```java - // Complile graph. + // Compile graph. if (!session.compileGraph(model)) { Log.e("MS_LITE", "Compile graph failed"); model.freeBuffer(); return false; } - // Note: when use model.freeBuffer(), the model can not be complile graph again. + // Note: when use model.freeBuffer(), the model can not be compile graph again. model.freeBuffer(); ``` diff --git a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java index 17ac8cd79b6..5a8d445e8e6 100644 --- a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java +++ b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java @@ -115,14 +115,14 @@ public class Posenet { } msConfig.free(); - // Complile graph. + // Compile graph. if (!session.compileGraph(model)) { Log.e("MS_LITE", "Compile graph failed"); model.freeBuffer(); return false; } - // Note: when use model.freeBuffer(), the model can not be complile graph again. + // Note: when use model.freeBuffer(), the model can not be compile graph again. model.freeBuffer(); return true; @@ -198,60 +198,12 @@ public class Posenet { String.format("Interpreter took %.2f ms", 1.0f * lastInferenceTimeNanos / 1_000_000) ); - // Get output tensor values. - List heatmaps_list = session.getOutputsByNodeName("Conv2D-27"); - if (heatmaps_list == null) { + float[][][][] heatmaps = runConv2Dfor27(); + float[][][][] offsets = runConv2Dfor28(); + + if (heatmaps == null || offsets ==null){ return null; } - MSTensor heatmaps_tensors = heatmaps_list.get(0); - - float[] heatmaps_results = heatmaps_tensors.getFloatData(); - int[] heatmapsShape = heatmaps_tensors.getShape(); //1, 9, 9 ,17 - - float[][][][] heatmaps = new float[heatmapsShape[0]][][][]; - for (int x = 0; x < heatmapsShape[0]; x++) { // heatmapsShape[0] =1 - float[][][] arrayThree = new float[heatmapsShape[1]][][]; - for (int y = 0; y < heatmapsShape[1]; y++) { // heatmapsShape[1] = 9 - float[][] arrayTwo = new float[heatmapsShape[2]][]; - for (int z = 0; z < heatmapsShape[2]; z++) { //heatmapsShape[2] = 9 - float[] arrayOne = new float[heatmapsShape[3]]; //heatmapsShape[3] = 17 - for (int i = 0; i < heatmapsShape[3]; i++) { - int n = i + z * heatmapsShape[3] + y * heatmapsShape[2] * heatmapsShape[3] + x * heatmapsShape[1] * heatmapsShape[2] * heatmapsShape[3]; - arrayOne[i] = heatmaps_results[n]; //1*9*9*17 ?? - } - arrayTwo[z] = arrayOne; - } - arrayThree[y] = arrayTwo; - } - heatmaps[x] = arrayThree; - } - - - List offsets_list = session.getOutputsByNodeName("Conv2D-28"); - if (offsets_list == null) { - return null; - } - MSTensor offsets_tensors = offsets_list.get(0); - float[] offsets_results = offsets_tensors.getFloatData(); - int[] offsetsShapes = offsets_tensors.getShape(); - - float[][][][] offsets = new float[offsetsShapes[0]][][][]; - for (int x = 0; x < offsetsShapes[0]; x++) { - float[][][] offsets_arrayThree = new float[offsetsShapes[1]][][]; - for (int y = 0; y < offsetsShapes[1]; y++) { - float[][] offsets_arrayTwo = new float[offsetsShapes[2]][]; - for (int z = 0; z < offsetsShapes[2]; z++) { - float[] offsets_arrayOne = new float[offsetsShapes[3]]; - for (int i = 0; i < offsetsShapes[3]; i++) { - int n = i + z * offsetsShapes[3] + y * offsetsShapes[2] * offsetsShapes[3] + x * offsetsShapes[1] * offsetsShapes[2] * offsetsShapes[3]; - offsets_arrayOne[i] = offsets_results[n]; - } - offsets_arrayTwo[z] = offsets_arrayOne; - } - offsets_arrayThree[y] = offsets_arrayTwo; - } - offsets[x] = offsets_arrayThree; - } int height = ((Object[]) heatmaps[0]).length; //9 int width = ((Object[]) heatmaps[0][0]).length; //9 @@ -288,8 +240,8 @@ public class Posenet { int positionY = (int) position.first; int positionX = (int) position.second; - yCoords[i] = ((float) positionY / (float) (height - 1) * bitmap.getHeight() + offsets[0][positionY][positionX][i]); - xCoords[i] = ((float) positionX / (float) (width - 1) * bitmap.getWidth() + offsets[0][positionY][positionX][i + numKeypoints]); + yCoords[i] = ((float) positionY / (float) (height - 1) * bitmap.getHeight() + offsets[0][positionY][positionX][i]); + xCoords[i] = ((float) positionX / (float) (width - 1) * bitmap.getWidth() + offsets[0][positionY][positionX][i + numKeypoints]); confidenceScores[i] = sigmoid(heatmaps[0][positionY][positionX][i]); } @@ -311,4 +263,72 @@ public class Posenet { return person; } + + private float[][][][] runConv2Dfor27() { + // Get output tensor values. + List heatmaps_list = session.getOutputsByNodeName("Conv2D-27"); + if (heatmaps_list == null) { + return null; + } + MSTensor heatmaps_tensors = heatmaps_list.get(0); + + float[] heatmaps_results = heatmaps_tensors.getFloatData(); + int[] heatmapsShape = heatmaps_tensors.getShape(); //1, 9, 9 ,17 + + if (heatmapsShape[0] < 0 || heatmapsShape[1] < 0 || heatmapsShape[2] < 0 || heatmapsShape[3] < 0) { + return null; + } + + float[][][][] heatmaps = new float[heatmapsShape[0]][][][]; + for (int x = 0; x < heatmapsShape[0]; x++) { // heatmapsShape[0] =1 + float[][][] arrayThree = new float[heatmapsShape[1]][][]; + for (int y = 0; y < heatmapsShape[1]; y++) { // heatmapsShape[1] = 9 + float[][] arrayTwo = new float[heatmapsShape[2]][]; + for (int z = 0; z < heatmapsShape[2]; z++) { //heatmapsShape[2] = 9 + float[] arrayOne = new float[heatmapsShape[3]]; //heatmapsShape[3] = 17 + for (int i = 0; i < heatmapsShape[3]; i++) { + int n = i + z * heatmapsShape[3] + y * heatmapsShape[2] * heatmapsShape[3] + x * heatmapsShape[1] * heatmapsShape[2] * heatmapsShape[3]; + arrayOne[i] = heatmaps_results[n]; //1*9*9*17 ?? + } + arrayTwo[z] = arrayOne; + } + arrayThree[y] = arrayTwo; + } + heatmaps[x] = arrayThree; + } + return heatmaps; + } + + + private float[][][][] runConv2Dfor28() { + List offsets_list = session.getOutputsByNodeName("Conv2D-28"); + if (offsets_list == null) { + return null; + } + MSTensor offsets_tensors = offsets_list.get(0); + float[] offsets_results = offsets_tensors.getFloatData(); + int[] offsetsShapes = offsets_tensors.getShape(); + + if (offsetsShapes[0] < 0 || offsetsShapes[1] < 0 || offsetsShapes[2] < 0 || offsetsShapes[3] < 0) { + return null; + } + float[][][][] offsets = new float[offsetsShapes[0]][][][]; + for (int x = 0; x < offsetsShapes[0]; x++) { + float[][][] offsets_arrayThree = new float[offsetsShapes[1]][][]; + for (int y = 0; y < offsetsShapes[1]; y++) { + float[][] offsets_arrayTwo = new float[offsetsShapes[2]][]; + for (int z = 0; z < offsetsShapes[2]; z++) { + float[] offsets_arrayOne = new float[offsetsShapes[3]]; + for (int i = 0; i < offsetsShapes[3]; i++) { + int n = i + z * offsetsShapes[3] + y * offsetsShapes[2] * offsetsShapes[3] + x * offsetsShapes[1] * offsetsShapes[2] * offsetsShapes[3]; + offsets_arrayOne[i] = offsets_results[n]; + } + offsets_arrayTwo[z] = offsets_arrayOne; + } + offsets_arrayThree[y] = offsets_arrayTwo; + } + offsets[x] = offsets_arrayThree; + } + return offsets; + } } diff --git a/model_zoo/official/lite/style_transfer/README.en.md b/model_zoo/official/lite/style_transfer/README.en.md index aa362e41d37..6dd526777f0 100644 --- a/model_zoo/official/lite/style_transfer/README.en.md +++ b/model_zoo/official/lite/style_transfer/README.en.md @@ -154,7 +154,7 @@ The inference code process of style transfer demo is as follows. For details abo - Load the model file and build a computational graph for inference. ```java - // Complile graph. + // Compile graph. if (!Predict_session.compileGraph(style_predict_model)) { Log.e("MS_LITE", "Compile style_predict graph failed"); style_predict_model.freeBuffer(); @@ -164,7 +164,7 @@ The inference code process of style transfer demo is as follows. For details abo style_transform_model.freeBuffer(); } - // Note: when use model.freeBuffer(), the model can not be complile graph again. + // Note: when use model.freeBuffer(), the model can not be compile graph again. style_predict_model.freeBuffer(); style_transform_model.freeBuffer(); ``` @@ -223,7 +223,7 @@ The inference code process of style transfer demo is as follows. For details abo // Get output tensor values. List tensorNames = Predict_session.getOutputTensorNames(); Map outputs = Predict_session.getOutputMapByTensor(); - Set> entrys = outputs.entrySet(); + Set> entry = outputs.entrySet(); float[] Predict_results = null; for (String tensorName : tensorNames) { diff --git a/model_zoo/official/lite/style_transfer/README.md b/model_zoo/official/lite/style_transfer/README.md index ca1aa9c0f5e..990b91b0050 100644 --- a/model_zoo/official/lite/style_transfer/README.md +++ b/model_zoo/official/lite/style_transfer/README.md @@ -157,7 +157,7 @@ - 加载模型文件并构建用于推理的计算图 ```java - // Complile graph. + // Compile graph. if (!Predict_session.compileGraph(style_predict_model)) { Log.e("MS_LITE", "Compile style_predict graph failed"); style_predict_model.freeBuffer(); @@ -167,7 +167,7 @@ style_transform_model.freeBuffer(); } - // Note: when use model.freeBuffer(), the model can not be complile graph again. + // Note: when use model.freeBuffer(), the model can not be compile graph again. style_predict_model.freeBuffer(); style_transform_model.freeBuffer(); ``` @@ -225,7 +225,7 @@ // Get output tensor values. List tensorNames = Predict_session.getOutputTensorNames(); Map outputs = Predict_session.getOutputMapByTensor(); - Set> entrys = outputs.entrySet(); + Set> entry = outputs.entrySet(); float[] Predict_results = null; for (String tensorName : tensorNames) { diff --git a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java index b3e771d3c24..7dd5e6e29f0 100644 --- a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java +++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java @@ -96,7 +96,7 @@ public class StyleTransferModelExecutor { msConfig.free(); - // Complile graph. + // Compile graph. if (!Predict_session.compileGraph(style_predict_model)) { Log.e("MS_LITE", "Compile style_predict graph failed"); style_predict_model.freeBuffer(); @@ -106,7 +106,7 @@ public class StyleTransferModelExecutor { style_transform_model.freeBuffer(); } - // Note: when use model.freeBuffer(), the model can not be complile graph again. + // Note: when use model.freeBuffer(), the model can not be compile graph again. style_predict_model.freeBuffer(); style_transform_model.freeBuffer(); } @@ -165,7 +165,7 @@ public class StyleTransferModelExecutor { // Get output tensor values. List tensorNames = Predict_session.getOutputTensorNames(); Map outputs = Predict_session.getOutputMapByTensor(); - Set> entrys = outputs.entrySet(); + Set> entry = outputs.entrySet(); float[] Predict_results = null; for (String tensorName : tensorNames) {