From 42c800251bc6cec320f984fd7d0ca8d2dff3b51e Mon Sep 17 00:00:00 2001 From: hangq Date: Mon, 24 Aug 2020 17:05:11 +0800 Subject: [PATCH] add getFloatData function --- mindspore/lite/java/build_aar.sh | 6 ++--- .../java/com/mindspore/lite/MSTensor.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mindspore/lite/java/build_aar.sh b/mindspore/lite/java/build_aar.sh index fd6faa86b4..c2b1251298 100644 --- a/mindspore/lite/java/build_aar.sh +++ b/mindspore/lite/java/build_aar.sh @@ -15,10 +15,10 @@ fi # copy arm64 so cd ${TOP_PATH}/output/ -rm -rf mindspore-lite-0.6.0 -tar -zxvf mindspore-lite-0.6.0-runtime-arm64-cpu.tar.gz +rm -rf mindspore-lite-0.7.0 +tar -zxvf mindspore-lite-0.7.0-runtime-arm64-cpu.tar.gz mkdir -p ${BASE_PATH}/lib/ -cp ${TOP_PATH}/output/mindspore-lite-0.6.0/lib/libmindspore-lite.so ${BASE_PATH}/lib/ +cp ${TOP_PATH}/output/mindspore-lite-0.7.0/lib/libmindspore-lite.so ${BASE_PATH}/lib/ cp ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so ${BASE_PATH}/lib/ # build jni so diff --git a/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/MSTensor.java b/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/MSTensor.java index 6092ab8ebc..3e4274e31e 100644 --- a/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/MSTensor.java +++ b/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/MSTensor.java @@ -16,6 +16,8 @@ package com.mindspore.lite; +import android.util.Log; + public class MSTensor { private long tensorPtr; @@ -52,6 +54,10 @@ public class MSTensor { return this.getData(this.tensorPtr); } + public float[] getFloatData() { + return decodeBytes(this.getData(this.tensorPtr)); + } + public void setData(byte[] data) { this.setData(this.tensorPtr, data, data.length); } @@ -69,6 +75,24 @@ public class MSTensor { this.tensorPtr = 0; } + private float[] decodeBytes(byte[] bytes) { + if (bytes.length % 4 != 0) { + Log.e("MS_LITE", "Length of bytes should be multi of 4 "); + return null; + } + int size = bytes.length / 4; + float[] ret = new float[size]; + for (int i = 0; i < size; i=i+4) { + int accNum = 0; + accNum = accNum | (bytes[i] & 0xff) << 0; + accNum = accNum | (bytes[i+1] & 0xff) << 8; + accNum = accNum | (bytes[i+2] & 0xff) << 16; + accNum = accNum | (bytes[i+3] & 0xff) << 24; + ret[i/4] = Float.intBitsToFloat(accNum); + } + return ret; + } + private native long createMSTensor(int dataType, int[] shape, int shapeLen); private native int[] getShape(long tensorPtr);