+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.mindspore.himindspore;
import android.Manifest;
@@ -11,7 +26,7 @@ import android.os.Build;
import android.os.Environment;
import android.util.Log;
import android.view.View;
-import android.widget.Button;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -19,25 +34,27 @@ import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;
+import com.alibaba.android.arouter.facade.annotation.Route;
+import com.alibaba.android.arouter.launcher.ARouter;
import com.mindspore.himindspore.base.BaseActivity;
-import com.mindspore.himindspore.imageclassification.ui.ImageMainActivity;
import com.mindspore.himindspore.mvp.MainContract;
import com.mindspore.himindspore.mvp.MainPresenter;
import com.mindspore.himindspore.net.FileDownLoadObserver;
import com.mindspore.himindspore.net.UpdateInfoBean;
-import com.mindspore.himindspore.objectdetection.ui.ObjectDetectionMainActivity;
import java.io.File;
-public class SplashActivity extends BaseActivity implements MainContract.View, View.OnClickListener {
+@Route(path = "/himindspore/SplashActivity")
+public class SplashActivity extends BaseActivity implements MainContract.View {
private static final String TAG = "SplashActivity";
private static final int REQUEST_PERMISSION = 1;
- private Button btnImage, btnObject, btnContract, btnAdvice;
private boolean isHasPermssion;
+ private int now_version;
private ProgressDialog progressDialog;
+ private TextView versionText;
private static final String CODE_URL = "https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/lite";
private static final String HELP_URL = "https://github.com/mindspore-ai/mindspore/issues";
@@ -46,17 +63,8 @@ public class SplashActivity extends BaseActivity implements MainC
@Override
protected void init() {
presenter = new MainPresenter(this);
-
- btnImage = findViewById(R.id.btn_image);
- btnObject = findViewById(R.id.btn_object);
- btnContract = findViewById(R.id.btn_contact);
- btnAdvice = findViewById(R.id.btn_advice);
-
- btnImage.setOnClickListener(this);
- btnObject.setOnClickListener(this);
- btnContract.setOnClickListener(this);
- btnAdvice.setOnClickListener(this);
-
+ versionText = findViewById(R.id.tv_vision);
+ showPackaeInfo();
requestPermissions();
getUpdateInfo();
}
@@ -66,6 +74,18 @@ public class SplashActivity extends BaseActivity implements MainC
return R.layout.activity_splash;
}
+ private void showPackaeInfo() {
+ try {
+ PackageManager packageManager = this.getPackageManager();
+ PackageInfo packageInfo = packageManager.getPackageInfo(this.getPackageName(), 0);
+ now_version = packageInfo.versionCode;
+ versionText.setText("Version: " + packageInfo.versionName);
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ }
+
private void requestPermissions() {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
@@ -87,27 +107,65 @@ public class SplashActivity extends BaseActivity implements MainC
}
- @Override
- public void onClick(View view) {
- if (R.id.btn_image == view.getId()) {
- if (isHasPermssion) {
- startActivity(new Intent(SplashActivity.this, ImageMainActivity.class));
- } else {
- requestPermissions();
- }
- } else if (R.id.btn_object == view.getId()) {
- if (isHasPermssion) {
- startActivity(new Intent(SplashActivity.this, ObjectDetectionMainActivity.class));
- } else {
- requestPermissions();
- }
- } else if (R.id.btn_contact == view.getId()) {
- openBrowser(CODE_URL);
- } else if (R.id.btn_advice == view.getId()) {
- openBrowser(HELP_URL);
+ public void onClickImage(View view) {
+ if (isHasPermssion) {
+ ARouter.getInstance().build("/imageobject/ImageCameraActivity")
+ .withInt("OPEN_TYPE", 1).navigation();
+ } else {
+ requestPermissions();
}
}
+ public void onClickGarbage(View view) {
+ if (isHasPermssion) {
+ ARouter.getInstance().build("/imageobject/ImageCameraActivity")
+ .withInt("OPEN_TYPE", 2).navigation();
+ } else {
+ requestPermissions();
+ }
+ }
+
+ public void onClickPhotoDetection(View view) {
+ if (isHasPermssion) {
+ ARouter.getInstance().build("/imageobject/ObjectPhotoActivity").navigation();
+ } else {
+ requestPermissions();
+ }
+ }
+
+ public void onClickCameraDetection(View view) {
+ if (isHasPermssion) {
+ ARouter.getInstance().build("/imageobject/ObjectCameraActivity").navigation();
+ } else {
+ requestPermissions();
+ }
+ }
+
+ public void onClickPoseNet(View view) {
+ if (isHasPermssion) {
+ ARouter.getInstance().build("/posenet/PosenetMainActivity").navigation(this);
+ } else {
+ requestPermissions();
+ }
+ }
+
+ public void onClickStyleTransfer(View view) {
+ if (isHasPermssion) {
+ ARouter.getInstance().build("/styletransfer/StyleMainActivity").navigation(this);
+ } else {
+ requestPermissions();
+ }
+ }
+
+ public void onClickSouceCode(View view) {
+ openBrowser(CODE_URL);
+ }
+
+ public void onClickHelp(View view) {
+ openBrowser(HELP_URL);
+ }
+
+
public void openBrowser(String url) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
@@ -160,16 +218,7 @@ public class SplashActivity extends BaseActivity implements MainC
}
- private int now_version;
-
public void showUpdate(final UpdateInfoBean updateInfo) {
- try {
- PackageManager packageManager = this.getPackageManager();
- PackageInfo packageInfo = packageManager.getPackageInfo(this.getPackageName(), 0);
- now_version = packageInfo.versionCode;
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
if (now_version == updateInfo.getVersionCode()) {
Toast.makeText(this, "已经是最新版本", Toast.LENGTH_SHORT).show();
@@ -245,4 +294,5 @@ public class SplashActivity extends BaseActivity implements MainC
return directoryPath;
}
+
}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BaseActivity.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BaseActivity.java
index 219ccea4d36..e7ad9d40567 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BaseActivity.java
+++ b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BaseActivity.java
@@ -1,3 +1,18 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.mindspore.himindspore.base;
import android.app.Activity;
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BasePresenter.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BasePresenter.java
index e1c2d841e91..f02b6501189 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BasePresenter.java
+++ b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/BasePresenter.java
@@ -1,3 +1,18 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.mindspore.himindspore.base;
public abstract class BasePresenter {
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/MyApplication.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/MyApplication.java
new file mode 100644
index 00000000000..25f42a8279b
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/MyApplication.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.himindspore.base;
+
+import android.app.Application;
+
+import com.alibaba.android.arouter.BuildConfig;
+import com.alibaba.android.arouter.launcher.ARouter;
+
+
+public class MyApplication extends Application {
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ if (BuildConfig.DEBUG) {
+ ARouter.openLog();
+ ARouter.openDebug();
+ }
+ ARouter.init(this);
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/TrackListener.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/TrackListener.java
deleted file mode 100644
index 5b78ab01db5..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/base/TrackListener.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.mindspore.himindspore.base;
-
-public interface TrackListener {
-}
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/ImageMainActivity.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/ImageMainActivity.java
deleted file mode 100644
index f5a8e4e1e17..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/ImageMainActivity.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.mindspore.himindspore.imageclassification.ui;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mindspore.himindspore.R;
-
-public class ImageMainActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_image_main);
-
-
- findViewById(R.id.btn_demo).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent(ImageMainActivity.this, ImageCameraActivity.class);
- intent.putExtra(ImageCameraActivity.OPEN_TYPE, ImageCameraActivity.TYPE_DEMO);
- startActivity(intent);
- }
- });
-
- findViewById(R.id.btn_custom).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent(ImageMainActivity.this, ImageCameraActivity.class);
- intent.putExtra(ImageCameraActivity.OPEN_TYPE, ImageCameraActivity.TYPE_CUSTOM);
- startActivity(intent);
- }
- });
- }
-}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainContract.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainContract.java
index ce91446ff7d..cd458e3e4e5 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainContract.java
+++ b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainContract.java
@@ -1,3 +1,18 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.mindspore.himindspore.mvp;
import com.mindspore.himindspore.net.FileDownLoadObserver;
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainPresenter.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainPresenter.java
index 36cb74f922a..3be6ba71917 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainPresenter.java
+++ b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/mvp/MainPresenter.java
@@ -1,4 +1,19 @@
package com.mindspore.himindspore.mvp;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import android.util.Log;
@@ -40,7 +55,7 @@ public class MainPresenter extends BasePresenter implements Main
@Override
public void onFailure(Call call, Throwable t) {
- Log.e(TAG, "onFailure" + t.toString());
+ Log.e(TAG, "onFailure>>>" + t.toString());
view.showFail(call.toString());
}
});
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectDetectionMainActivity.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectDetectionMainActivity.java
deleted file mode 100644
index a0807e54a7f..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectDetectionMainActivity.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.mindspore.himindspore.objectdetection.ui;
-
-import android.Manifest;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.app.ActivityCompat;
-
-import com.mindspore.himindspore.R;
-
-public class ObjectDetectionMainActivity extends AppCompatActivity implements View.OnClickListener {
-
- private static final int REQUEST_CAMERA_PERMISSION = 2;
- private static final int REQUEST_PHOTO_PERMISSION = 3;
-
- private Button btnPhoto, btnCamera;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_object_detection_main);
-
- btnPhoto = findViewById(R.id.btn_photo);
- btnCamera = findViewById(R.id.btn_camera);
-
- btnPhoto.setOnClickListener(this);
- btnCamera.setOnClickListener(this);
- }
-
-
- @Override
- public void onClick(View view) {
- if (R.id.btn_photo == view.getId()) {
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
- Manifest.permission.READ_PHONE_STATE}, REQUEST_PHOTO_PERMISSION);
- } else if (R.id.btn_camera == view.getId()) {
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
- Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
- }
- }
-
- /**
- * Authority application result callback
- */
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- if (REQUEST_PHOTO_PERMISSION == requestCode) {
- choosePhoto();
- } else if (REQUEST_CAMERA_PERMISSION == requestCode) {
- chooseCamera();
- }
- }
-
-
- private void choosePhoto() {
- Intent intent = new Intent(ObjectDetectionMainActivity.this, ObjectPhotoActivity.class);
- startActivity(intent);
- }
-
- private void chooseCamera() {
- Intent intent = new Intent(ObjectDetectionMainActivity.this, ObjectCameraActivity.class);
- startActivity(intent);
- }
-}
-
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/track/TrackListener.java b/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/track/TrackListener.java
deleted file mode 100644
index f9697c3e997..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/track/TrackListener.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.mindspore.himindspore.track;
-
-public interface TrackListener {
-}
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_audio.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_audio.png
new file mode 100644
index 00000000000..45b1bd4ea27
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_audio.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_code.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_code.png
index 40eda4c16dc..c229406d80f 100644
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_code.png and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_code.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_commend.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_commend.png
new file mode 100644
index 00000000000..b92cde0a790
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_commend.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_help.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_help.png
index 72612afbcc6..3065f4f0542 100644
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_help.png and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_help.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_image.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_image.png
index 1f41411f51a..a5e78d02d27 100644
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_image.png and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_image.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_object.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_object.png
index 52bc74717ad..5fce1480701 100644
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_object.png and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_object.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_other.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_other.png
new file mode 100644
index 00000000000..924bfdbe115
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_other.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_text.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_text.png
new file mode 100644
index 00000000000..35f396e7c88
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable-xxhdpi/btn_text.png differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_code.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_code.png
deleted file mode 100644
index 9ec5a41cf5b..00000000000
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_code.png and /dev/null differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_help.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_help.png
deleted file mode 100644
index 67c28d7cb5d..00000000000
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_help.png and /dev/null differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_image.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_image.png
deleted file mode 100644
index eb82c1ad465..00000000000
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_image.png and /dev/null differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_object.png b/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_object.png
deleted file mode 100644
index 94b8a7323bd..00000000000
Binary files a/model_zoo/official/lite/Himindspore/app/src/main/res/drawable/btn_object.png and /dev/null differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_contract.xml b/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_contract.xml
deleted file mode 100644
index f34a8c35db6..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_contract.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_image_main.xml b/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_image_main.xml
deleted file mode 100644
index f2fe9735b78..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_image_main.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_main.xml b/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_main.xml
deleted file mode 100644
index a4e8d403ba2..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_main.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_object_detection_main.xml b/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_object_detection_main.xml
deleted file mode 100644
index 5701ce92173..00000000000
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_object_detection_main.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_splash.xml b/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_splash.xml
index 4bcb57ebdee..20eda835472 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_splash.xml
+++ b/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_splash.xml
@@ -7,11 +7,12 @@
android:background="@color/colorPrimary"
tools:context=".SplashActivity">
+
-
+ app:layout_constraintTop_toBottomOf="@+id/title"
+ app:layout_constraintWidth_percent="0.43" />
+
+
+ android:textSize="12sp"
+ app:layout_constraintStart_toStartOf="@+id/btn_image"
+ app:layout_constraintTop_toBottomOf="@+id/btn_image"
+ app:layout_constraintWidth_percent="0.43" />
+
+
+
+
+
+
+
+ android:textSize="12sp"
+ app:layout_constraintStart_toStartOf="@+id/btn_posenet"
+ app:layout_constraintTop_toBottomOf="@+id/btn_posenet"
+ app:layout_constraintWidth_percent="0.43" />
+
+
-
+ tools:text="Version 1.0.0" />
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/values/strings.xml b/model_zoo/official/lite/Himindspore/app/src/main/res/values/strings.xml
index 2bd71793511..69bc2200ca7 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/values/strings.xml
+++ b/model_zoo/official/lite/Himindspore/app/src/main/res/values/strings.xml
@@ -4,7 +4,11 @@
customImage Classification
- Object Detection
+ Garbage Classification
+ Photo Detection
+ Camera Detection
+ PoseNet
+ Style TransferSource CodeHelp And FeedBack
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/xml/file_paths.xml b/model_zoo/official/lite/Himindspore/app/src/main/res/xml/file_paths.xml
index 7b4a522eb9a..1d21aa9902b 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/xml/file_paths.xml
+++ b/model_zoo/official/lite/Himindspore/app/src/main/res/xml/file_paths.xml
@@ -1,9 +1,10 @@
-
+
-
+ path="files_root">
diff --git a/model_zoo/official/lite/Himindspore/app/src/test/java/com/mindspore/himindspore/ExampleUnitTest.java b/model_zoo/official/lite/Himindspore/app/src/test/java/com/mindspore/himindspore/ExampleUnitTest.java
index bae54862a6f..daeb93b7aaf 100644
--- a/model_zoo/official/lite/Himindspore/app/src/test/java/com/mindspore/himindspore/ExampleUnitTest.java
+++ b/model_zoo/official/lite/Himindspore/app/src/test/java/com/mindspore/himindspore/ExampleUnitTest.java
@@ -2,7 +2,7 @@ package com.mindspore.himindspore;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
/**
* Example local unit test, which will execute on the development machine (host).
diff --git a/model_zoo/official/lite/Himindspore/gradle.properties b/model_zoo/official/lite/Himindspore/gradle.properties
index c52ac9b7971..f5020a3b373 100644
--- a/model_zoo/official/lite/Himindspore/gradle.properties
+++ b/model_zoo/official/lite/Himindspore/gradle.properties
@@ -16,4 +16,5 @@ org.gradle.jvmargs=-Xmx2048m
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
-android.enableJetifier=true
\ No newline at end of file
+android.enableJetifier=true
+android.injected.testOnly=false
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/.gitignore b/model_zoo/official/lite/Himindspore/imageObject/.gitignore
new file mode 100644
index 00000000000..42afabfd2ab
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/CMakeLists.txt b/model_zoo/official/lite/Himindspore/imageObject/CMakeLists.txt
similarity index 81%
rename from model_zoo/official/lite/Himindspore/app/CMakeLists.txt
rename to model_zoo/official/lite/Himindspore/imageObject/CMakeLists.txt
index 7aebd0a5a1b..99ab0370c89 100644
--- a/model_zoo/official/lite/Himindspore/app/CMakeLists.txt
+++ b/model_zoo/official/lite/Himindspore/imageObject/CMakeLists.txt
@@ -6,9 +6,9 @@
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI})
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI})
-set(MINDSPORELITE_VERSION mindspore-lite-1.0.1-runtime-arm64-cpu)
+set(MINDSPORELITE_VERSION mindspore-lite-1.0.1-runtime-arm64-cpu)
# ============== Set MindSpore Dependencies. =============
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp)
@@ -19,16 +19,16 @@ include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/in
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/include/schema)
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/minddata/include)
-add_library(mindspore-lite SHARED IMPORTED )
-add_library(minddata-lite SHARED IMPORTED )
-add_library(libmindspore-lite-fp16 SHARED IMPORTED )
+add_library(mindspore-lite SHARED IMPORTED)
+add_library(minddata-lite SHARED IMPORTED)
+#add_library(libmindspore-lite-fp16 SHARED IMPORTED )
set_target_properties(mindspore-lite PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libmindspore-lite.so)
set_target_properties(minddata-lite PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/minddata/lib/libminddata-lite.so)
-set_target_properties(libmindspore-lite-fp16 PROPERTIES IMPORTED_LOCATION
- ${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libmindspore-lite-fp16.so)
+#set_target_properties(libmindspore-lite-fp16 PROPERTIES IMPORTED_LOCATION
+# ${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libmindspore-lite-fp16.so)
# --------------- MindSpore Lite set End. --------------------
@@ -37,7 +37,7 @@ set_target_properties(libmindspore-lite-fp16 PROPERTIES IMPORTED_LOCATION
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
-file(GLOB_RECURSE cpp_src "src/main/cpp/*.cpp" "src/main/cpp/*.h")
+file(GLOB_RECURSE cpp_src "src/main/cpp/*.cpp" "src/main/cpp/*.h")
add_library( # Sets the name of the library.
mlkit-label-MS
@@ -60,10 +60,10 @@ find_library( # Sets the name of the path variable.
# Specifies the name of the NDK library that
# you want CMake to locate.
- log )
+ log)
-find_library( jnigraphics-lib jnig·raphics )
+find_library(jnigraphics-lib jnig·raphics)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
@@ -75,7 +75,7 @@ target_link_libraries( # Specifies the target library.
# --- mindspore ---
minddata-lite
mindspore-lite
- libmindspore-lite-fp16
+ # libmindspore-lite-fp16
# --- other dependencies.---
-ljnigraphics
diff --git a/model_zoo/official/lite/Himindspore/imageObject/build.gradle b/model_zoo/official/lite/Himindspore/imageObject/build.gradle
new file mode 100644
index 00000000000..6fdaec426e4
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/build.gradle
@@ -0,0 +1,83 @@
+plugins {
+ id 'com.android.library'
+}
+
+android {
+ compileSdkVersion 30
+ buildToolsVersion "30.0.1"
+
+ defaultConfig {
+ minSdkVersion 21
+ targetSdkVersion 30
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles "consumer-rules.pro"
+ javaCompileOptions {
+ annotationProcessorOptions {
+ arguments = [moduleName: project.getName()]
+ }
+ }
+ externalNativeBuild {
+ cmake {
+ arguments "-DANDROID_STL=c++_shared"
+ cppFlags "-std=c++17"
+ }
+
+ }
+ ndk {
+ abiFilters 'arm64-v8a'
+ }
+ }
+
+ aaptOptions {
+ noCompress '.so', 'ms'
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+
+ externalNativeBuild {
+ cmake {
+ path file('CMakeLists.txt')
+ }
+ }
+ ndkVersion '21.3.6528147'
+
+ sourceSets {
+ main {
+ jniLibs.srcDirs = ['libs']
+ }
+ }
+ packagingOptions {
+ pickFirst 'lib/arm64-v8a/libmlkit-label-MS.so'
+ exclude 'lib/arm64-v8a/libmindspore-lite.so'
+
+ }
+}
+
+// Download default models; if you wish to use your own models then
+// place them in the "assets" directory and comment out this line.
+apply from: 'download.gradle'
+
+dependencies {
+
+ implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'com.google.android.material:material:1.2.1'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
+ testImplementation 'junit:junit:4.+'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.2'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
+
+ implementation 'com.alibaba:arouter-api:1.2.1'
+ annotationProcessor 'com.alibaba:arouter-compiler:1.1.2'
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/consumer-rules.pro b/model_zoo/official/lite/Himindspore/imageObject/consumer-rules.pro
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/model_zoo/official/lite/Himindspore/app/download.gradle b/model_zoo/official/lite/Himindspore/imageObject/download.gradle
similarity index 96%
rename from model_zoo/official/lite/Himindspore/app/download.gradle
rename to model_zoo/official/lite/Himindspore/imageObject/download.gradle
index 988e6c78d87..798e69884cf 100644
--- a/model_zoo/official/lite/Himindspore/app/download.gradle
+++ b/model_zoo/official/lite/Himindspore/imageObject/download.gradle
@@ -74,21 +74,21 @@ task cleanUnusedmindsporeFiles(type: Delete, dependsOn: ['unzipMindSporeInclude'
* Using preBuild to download mindspore library and model file.
* Run before gradle build.
*/
-if (file("src/main/cpp/${mindsporeLite_Version}/lib/libmindspore-lite.so").exists()){
+if (file("src/main/cpp/${mindsporeLite_Version}/lib/libmindspore-lite.so").exists()) {
downloadMindSporeLibrary.enabled = false
unzipMindSporeInclude.enabled = false
cleanUnusedmindsporeFiles.enabled = false
}
-if (file("src/main/assets/model/garbage_mobilenetv2.ms").exists()){
+if (file("src/main/assets/model/garbage_mobilenetv2.ms").exists()) {
downloadGarbageModelFile.enabled = false
}
-if (file("src/main/assets/model/mobilenetv2.ms").exists()){
+if (file("src/main/assets/model/mobilenetv2.ms").exists()) {
downloadModelFile.enabled = false
}
-if (file("src/main/assets/model/ssd.ms").exists()){
+if (file("src/main/assets/model/ssd.ms").exists()) {
downloadObjectModelFile.enabled = false
}
diff --git a/model_zoo/official/lite/Himindspore/imageObject/proguard-rules.pro b/model_zoo/official/lite/Himindspore/imageObject/proguard-rules.pro
new file mode 100644
index 00000000000..481bb434814
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/androidTest/java/com/mindspore/imageobject/ExampleInstrumentedTest.java b/model_zoo/official/lite/Himindspore/imageObject/src/androidTest/java/com/mindspore/imageobject/ExampleInstrumentedTest.java
new file mode 100644
index 00000000000..d00500af303
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/androidTest/java/com/mindspore/imageobject/ExampleInstrumentedTest.java
@@ -0,0 +1,26 @@
+package com.mindspore.imageobject;
+
+import android.content.Context;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ assertEquals("com.mindspore.imageobject.test", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/AndroidManifest.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/AndroidManifest.xml
new file mode 100644
index 00000000000..e9c7710c6cb
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/AndroidManifest.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/GarbageMindSporeNetnative.cpp b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/GarbageMindSporeNetnative.cpp
similarity index 89%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/GarbageMindSporeNetnative.cpp
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/GarbageMindSporeNetnative.cpp
index d454acdfc6c..ad79a2ca236 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/cpp/GarbageMindSporeNetnative.cpp
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/GarbageMindSporeNetnative.cpp
@@ -85,8 +85,9 @@ char *CreateLocalModelBuffer(JNIEnv *env, jobject modelBuffer) {
* @param msOutputs
* @return
*/
-std::string GarbageProcessRunnetResult(const int RET_CATEGORY_SUM, const char *const labels_name_map[],
- std::unordered_map msOutputs) {
+std::string
+GarbageProcessRunnetResult(const int RET_CATEGORY_SUM, const char *const labels_name_map[],
+ std::unordered_map msOutputs) {
// Get the branch of the model output.
// Use iterators to get map elements.
std::unordered_map::iterator iter;
@@ -110,17 +111,17 @@ std::string GarbageProcessRunnetResult(const int RET_CATEGORY_SUM, const char *c
// Converted to text information that needs to be displayed in the APP.
std::string categoryScore = "";
if (maxIndex <= 9) {
- categoryScore += labels_name_grbage_sort_map[0];
- categoryScore += ":";
+ categoryScore += labels_name_grbage_sort_map[0];
+ categoryScore += ":";
} else if (maxIndex > 9 && maxIndex <= 17) {
- categoryScore += labels_name_grbage_sort_map[1];
- categoryScore += ":";
+ categoryScore += labels_name_grbage_sort_map[1];
+ categoryScore += ":";
} else if (maxIndex > 17 && maxIndex <= 21) {
- categoryScore += labels_name_grbage_sort_map[2];
- categoryScore += ":";
+ categoryScore += labels_name_grbage_sort_map[2];
+ categoryScore += ":";
} else if (maxIndex > 21 && maxIndex <= 25) {
- categoryScore += labels_name_grbage_sort_map[3];
- categoryScore += ":";
+ categoryScore += labels_name_grbage_sort_map[3];
+ categoryScore += ":";
}
categoryScore += labels_name_map[maxIndex];
return categoryScore;
@@ -198,10 +199,10 @@ bool PreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_mat_ptr
*/
extern "C"
JNIEXPORT jlong JNICALL
-Java_com_mindspore_himindspore_imageclassification_help_GarbageTrackingMobile_loadModel(JNIEnv *env,
- jobject thiz,
- jobject model_buffer,
- jint num_thread) {
+Java_com_mindspore_imageobject_imageclassification_help_GarbageTrackingMobile_loadModel(JNIEnv *env,
+ jobject thiz,
+ jobject model_buffer,
+ jint num_thread) {
if (nullptr == model_buffer) {
MS_PRINT("error, buffer is nullptr!");
return (jlong) nullptr;
@@ -248,9 +249,10 @@ Java_com_mindspore_himindspore_imageclassification_help_GarbageTrackingMobile_lo
* sending a picture to the model and run inference.
*/
extern "C" JNIEXPORT jstring JNICALL
-Java_com_mindspore_himindspore_imageclassification_help_GarbageTrackingMobile_runNet(JNIEnv *env, jclass type,
- jlong netEnv,
- jobject srcBitmap) {
+Java_com_mindspore_imageobject_imageclassification_help_GarbageTrackingMobile_runNet(JNIEnv *env,
+ jclass type,
+ jlong netEnv,
+ jobject srcBitmap) {
LiteMat lite_mat_bgr, lite_norm_mat_cut;
if (!BitmapToLiteMat(env, srcBitmap, &lite_mat_bgr)) {
@@ -315,16 +317,18 @@ Java_com_mindspore_himindspore_imageclassification_help_GarbageTrackingMobile_ru
}
std::string resultStr = GarbageProcessRunnetResult(::RET_GARBAGE_DETAILED_SUM,
- ::labels_name_grbage_detailed_map, msOutputs);
+ ::labels_name_grbage_detailed_map,
+ msOutputs);
const char *resultCharData = resultStr.c_str();
return (env)->NewStringUTF(resultCharData);
}
extern "C" JNIEXPORT jboolean JNICALL
-Java_com_mindspore_himindspore_imageclassification_help_GarbageTrackingMobile_unloadModel(JNIEnv *env,
- jclass type,
- jlong netEnv) {
+Java_com_mindspore_imageobject_imageclassification_help_GarbageTrackingMobile_unloadModel(
+ JNIEnv *env,
+ jclass type,
+ jlong netEnv) {
MS_PRINT("MindSpore release net.");
void **labelEnv = reinterpret_cast(netEnv);
if (labelEnv == nullptr) {
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/GarbageMindSporeNetnative.h b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/GarbageMindSporeNetnative.h
similarity index 100%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/GarbageMindSporeNetnative.h
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/GarbageMindSporeNetnative.h
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/ImageMindSporeNetnative.cpp b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ImageMindSporeNetnative.cpp
similarity index 99%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/ImageMindSporeNetnative.cpp
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ImageMindSporeNetnative.cpp
index c0ff59ae614..903ef01e5b4 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/cpp/ImageMindSporeNetnative.cpp
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ImageMindSporeNetnative.cpp
@@ -671,7 +671,7 @@ bool ImagePreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_ma
*/
extern "C"
JNIEXPORT jlong JNICALL
-Java_com_mindspore_himindspore_imageclassification_help_ImageTrackingMobile_loadModel(JNIEnv *env,
+Java_com_mindspore_imageobject_imageclassification_help_ImageTrackingMobile_loadModel(JNIEnv *env,
jobject thiz,
jobject model_buffer,
jint num_thread) {
@@ -721,7 +721,7 @@ Java_com_mindspore_himindspore_imageclassification_help_ImageTrackingMobile_load
* sending a picture to the model and run inference.
*/
extern "C" JNIEXPORT jstring JNICALL
-Java_com_mindspore_himindspore_imageclassification_help_ImageTrackingMobile_runNet(JNIEnv *env,
+Java_com_mindspore_imageobject_imageclassification_help_ImageTrackingMobile_runNet(JNIEnv *env,
jclass type,
jlong netEnv,
jobject srcBitmap) {
@@ -795,7 +795,7 @@ Java_com_mindspore_himindspore_imageclassification_help_ImageTrackingMobile_runN
}
extern "C" JNIEXPORT jboolean JNICALL
-Java_com_mindspore_himindspore_imageclassification_help_ImageTrackingMobile_unloadModel(JNIEnv *env,
+Java_com_mindspore_imageobject_imageclassification_help_ImageTrackingMobile_unloadModel(JNIEnv *env,
jclass type,
jlong netEnv) {
MS_PRINT("MindSpore release net.");
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/ImageMindSporeNetnative.h b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ImageMindSporeNetnative.h
similarity index 100%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/ImageMindSporeNetnative.h
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ImageMindSporeNetnative.h
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/MSNetWork.cpp b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/MSNetWork.cpp
similarity index 53%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/MSNetWork.cpp
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/MSNetWork.cpp
index 0c9d8f660f1..ad02a1c59a5 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/cpp/MSNetWork.cpp
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/MSNetWork.cpp
@@ -26,37 +26,38 @@ MSNetWork::MSNetWork(void) : session_(nullptr), model_(nullptr) {}
MSNetWork::~MSNetWork(void) {}
-void MSNetWork::CreateSessionMS(char *modelBuffer, size_t bufferLen, mindspore::lite::Context *ctx) {
- session_ = mindspore::session::LiteSession::CreateSession(ctx);
- if (session_ == nullptr) {
- MS_PRINT("Create Session failed.");
- return;
- }
+void
+MSNetWork::CreateSessionMS(char *modelBuffer, size_t bufferLen, mindspore::lite::Context *ctx) {
+ session_ = mindspore::session::LiteSession::CreateSession(ctx);
+ if (session_ == nullptr) {
+ MS_PRINT("Create Session failed.");
+ return;
+ }
- // Compile model.
- model_ = mindspore::lite::Model::Import(modelBuffer, bufferLen);
- if (model_ == nullptr) {
- ReleaseNets();
- MS_PRINT("Import model failed.");
- return;
- }
+ // Compile model.
+ model_ = mindspore::lite::Model::Import(modelBuffer, bufferLen);
+ if (model_ == nullptr) {
+ ReleaseNets();
+ MS_PRINT("Import model failed.");
+ return;
+ }
- int ret = session_->CompileGraph(model_);
- if (ret != mindspore::lite::RET_OK) {
- ReleaseNets();
- MS_PRINT("CompileGraph failed.");
- return;
- }
+ int ret = session_->CompileGraph(model_);
+ if (ret != mindspore::lite::RET_OK) {
+ ReleaseNets();
+ MS_PRINT("CompileGraph failed.");
+ return;
+ }
}
void MSNetWork::ReleaseNets(void) {
- if (model_ != nullptr) {
- model_->Free();
- delete model_;
- model_ = nullptr;
- }
- if (session_ != nullptr) {
- delete session_;
- session_ = nullptr;
- }
+ if (model_ != nullptr) {
+ model_->Free();
+ delete model_;
+ model_ = nullptr;
+ }
+ if (session_ != nullptr) {
+ delete session_;
+ session_ = nullptr;
+ }
}
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/MSNetWork.h b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/MSNetWork.h
similarity index 99%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/MSNetWork.h
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/MSNetWork.h
index 5078731b7ec..5daef29a794 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/cpp/MSNetWork.h
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/MSNetWork.h
@@ -53,8 +53,10 @@ class MSNetWork {
void ReleaseNets(void);
mindspore::session::LiteSession *session() const { return session_; }
+
private:
mindspore::session::LiteSession *session_;
mindspore::lite::Model *model_;
};
+
#endif
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ObjectMindSporeNetnative.cpp b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ObjectMindSporeNetnative.cpp
new file mode 100644
index 00000000000..a50daf6b51b
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ObjectMindSporeNetnative.cpp
@@ -0,0 +1,270 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "include/errorcode.h"
+#include "include/ms_tensor.h"
+#include "MSNetWork.h"
+#include "ssd_util/ssd_util.h"
+#include "lite_cv/lite_mat.h"
+#include "lite_cv/image_process.h"
+
+using mindspore::dataset::LiteMat;
+using mindspore::dataset::LPixelType;
+using mindspore::dataset::LDataType;
+#define MS_PRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MSJNI", format, ##__VA_ARGS__)
+
+bool ObjectBitmapToLiteMat(JNIEnv *env, const jobject &srcBitmap, LiteMat *lite_mat) {
+ bool ret = false;
+ AndroidBitmapInfo info;
+ void *pixels = nullptr;
+ LiteMat &lite_mat_bgr = *lite_mat;
+ AndroidBitmap_getInfo(env, srcBitmap, &info);
+ if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
+ MS_PRINT("Image Err, Request RGBA");
+ return false;
+ }
+ AndroidBitmap_lockPixels(env, srcBitmap, &pixels);
+ if (info.stride == info.width * 4) {
+ ret = InitFromPixel(reinterpret_cast(pixels),
+ LPixelType::RGBA2RGB, LDataType::UINT8,
+ info.width, info.height, lite_mat_bgr);
+ if (!ret) {
+ MS_PRINT("Init From RGBA error");
+ }
+ } else {
+ unsigned char *pixels_ptr = new unsigned char[info.width * info.height * 4];
+ unsigned char *ptr = pixels_ptr;
+ unsigned char *data = reinterpret_cast(pixels);
+ for (int i = 0; i < info.height; i++) {
+ memcpy(ptr, data, info.width * 4);
+ ptr += info.width * 4;
+ data += info.stride;
+ }
+ ret = InitFromPixel(reinterpret_cast(pixels_ptr),
+ LPixelType::RGBA2RGB, LDataType::UINT8,
+ info.width, info.height, lite_mat_bgr);
+ if (!ret) {
+ MS_PRINT("Init From RGBA error");
+ }
+ delete[] (pixels_ptr);
+ }
+ AndroidBitmap_unlockPixels(env, srcBitmap);
+ return ret;
+}
+
+bool ObjectPreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_mat_ptr) {
+ bool ret = false;
+ LiteMat lite_mat_resize;
+ LiteMat &lite_norm_mat_cut = *lite_norm_mat_ptr;
+ ret = ResizeBilinear(lite_mat_bgr, lite_mat_resize, 300, 300);
+ if (!ret) {
+ MS_PRINT("ResizeBilinear error");
+ return false;
+ }
+ LiteMat lite_mat_convert_float;
+ ret = ConvertTo(lite_mat_resize, lite_mat_convert_float, 1.0 / 255.0);
+ if (!ret) {
+ MS_PRINT("ConvertTo error");
+ return false;
+ }
+
+ std::vector means = {0.485, 0.456, 0.406};
+ std::vector stds = {0.229, 0.224, 0.225};
+ SubStractMeanNormalize(lite_mat_convert_float, lite_norm_mat_cut, means, stds);
+ return true;
+}
+
+char *ObjectCreateLocalModelBuffer(JNIEnv *env, jobject modelBuffer) {
+ jbyte *modelAddr = static_cast(env->GetDirectBufferAddress(modelBuffer));
+ int modelLen = static_cast(env->GetDirectBufferCapacity(modelBuffer));
+ char *buffer(new char[modelLen]);
+ memcpy(buffer, modelAddr, modelLen);
+ return buffer;
+}
+
+/**
+ *
+ * @param msOutputs Model output, the mindspore inferencing result.
+ * @param srcImageWidth The width of the original input image.
+ * @param srcImageHeight The height of the original input image.
+ * @return
+ */
+std::string
+ProcessRunnetResult(std::unordered_map msOutputs,
+ int srcImageWidth, int srcImageHeight) {
+ std::unordered_map::iterator iter;
+ iter = msOutputs.begin();
+ auto branch2_string = iter->first;
+ auto branch2_tensor = iter->second;
+
+ ++iter;
+ auto branch1_string = iter->first;
+ auto branch1_tensor = iter->second;
+ MS_PRINT("%s %s", branch1_string.c_str(), branch2_string.c_str());
+
+ // ----------- 接口测试 --------------------------
+ float *tmpscores2 = reinterpret_cast(branch1_tensor->MutableData());
+ float *tmpdata = reinterpret_cast(branch2_tensor->MutableData());
+
+ // Using ssd model util to process model branch outputs.
+ SSDModelUtil ssdUtil(srcImageWidth, srcImageHeight);
+
+ std::string retStr = ssdUtil.getDecodeResult(tmpscores2, tmpdata);
+ MS_PRINT("retStr %s", retStr.c_str());
+
+ return retStr;
+}
+
+extern "C" JNIEXPORT jlong JNICALL
+Java_com_mindspore_imageobject_objectdetection_help_ObjectTrackingMobile_loadModel(JNIEnv *env,
+ jobject thiz,
+ jobject assetManager,
+ jobject buffer,
+ jint numThread) {
+ MS_PRINT("MindSpore so version 20200730");
+ if (nullptr == buffer) {
+ MS_PRINT("error, buffer is nullptr!");
+ return (jlong) nullptr;
+ }
+ jlong bufferLen = env->GetDirectBufferCapacity(buffer);
+ MS_PRINT("MindSpore get bufferLen:%d", static_cast(bufferLen));
+ if (0 == bufferLen) {
+ MS_PRINT("error, bufferLen is 0!");
+ return (jlong) nullptr;
+ }
+
+ char *modelBuffer = ObjectCreateLocalModelBuffer(env, buffer);
+ if (modelBuffer == nullptr) {
+ MS_PRINT("modelBuffer create failed!");
+ return (jlong) nullptr;
+ }
+
+ MS_PRINT("MindSpore loading Model.");
+ void **labelEnv = new void *;
+ MSNetWork *labelNet = new MSNetWork;
+ *labelEnv = labelNet;
+
+ mindspore::lite::Context *context = new mindspore::lite::Context;
+ context->thread_num_ = numThread;
+
+ labelNet->CreateSessionMS(modelBuffer, bufferLen, context);
+ delete context;
+ if (labelNet->session() == nullptr) {
+ delete labelNet;
+ delete labelEnv;
+ MS_PRINT("MindSpore create session failed!.");
+ return (jlong) nullptr;
+ }
+ MS_PRINT("MindSpore create session successfully.");
+
+ if (buffer != nullptr) {
+ env->DeleteLocalRef(buffer);
+ }
+
+ if (assetManager != nullptr) {
+ env->DeleteLocalRef(assetManager);
+ }
+ MS_PRINT("ptr released successfully.");
+
+ return (jlong) labelEnv;
+}
+
+
+extern "C" JNIEXPORT jstring JNICALL
+Java_com_mindspore_imageobject_objectdetection_help_ObjectTrackingMobile_runNet(JNIEnv *env,
+ jobject thiz,
+ jlong netEnv,
+ jobject srcBitmap) {
+ LiteMat lite_mat_bgr, lite_norm_mat_cut;
+
+ if (!ObjectBitmapToLiteMat(env, srcBitmap, &lite_mat_bgr)) {
+ MS_PRINT("ObjectBitmapToLiteMat error");
+ return NULL;
+ }
+ int srcImageWidth = lite_mat_bgr.width_;
+ int srcImageHeight = lite_mat_bgr.height_;
+ if (!ObjectPreProcessImageData(lite_mat_bgr, &lite_norm_mat_cut)) {
+ MS_PRINT("ObjectPreProcessImageData error");
+ return NULL;
+ }
+
+ ImgDims inputDims;
+ inputDims.channel = lite_norm_mat_cut.channel_;
+ inputDims.width = lite_norm_mat_cut.width_;
+ inputDims.height = lite_norm_mat_cut.height_;
+
+ // Get the mindsore inference environment which created in loadModel().
+ void **labelEnv = reinterpret_cast(netEnv);
+ if (labelEnv == nullptr) {
+ MS_PRINT("MindSpore error, labelEnv is a nullptr.");
+ return NULL;
+ }
+ MSNetWork *labelNet = static_cast(*labelEnv);
+
+ auto mSession = labelNet->session();
+ if (mSession == nullptr) {
+ MS_PRINT("MindSpore error, Session is a nullptr.");
+ return NULL;
+ }
+ MS_PRINT("MindSpore get session.");
+
+ auto msInputs = mSession->GetInputs();
+ auto inTensor = msInputs.front();
+ float *dataHWC = reinterpret_cast(lite_norm_mat_cut.data_ptr_);
+ // copy input Tensor
+ memcpy(inTensor->MutableData(), dataHWC,
+ inputDims.channel * inputDims.width * inputDims.height * sizeof(float));
+ MS_PRINT("MindSpore get msInputs.");
+
+ auto status = mSession->RunGraph();
+ if (status != mindspore::lite::RET_OK) {
+ MS_PRINT("MindSpore runnet error.");
+ return NULL;
+ }
+
+ auto names = mSession->GetOutputTensorNames();
+ std::unordered_map msOutputs;
+ for (const auto &name : names) {
+ auto temp_dat = mSession->GetOutputByTensorName(name);
+ msOutputs.insert(std::pair{name, temp_dat});
+ }
+ std::string retStr = ProcessRunnetResult(msOutputs, srcImageWidth, srcImageHeight);
+ const char *resultChardata = retStr.c_str();
+
+ return (env)->NewStringUTF(resultChardata);
+}
+
+
+extern "C"
+JNIEXPORT jboolean JNICALL
+Java_com_mindspore_imageobject_objectdetection_help_ObjectTrackingMobile_unloadModel(JNIEnv *env,
+ jobject thiz,
+ jlong netEnv) {
+ void **labelEnv = reinterpret_cast(netEnv);
+ MSNetWork *labelNet = static_cast(*labelEnv);
+ labelNet->ReleaseNets();
+ return (jboolean) true;
+}
+
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/ssd_util/ssd_util.cpp b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ssd_util/ssd_util.cpp
similarity index 95%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/ssd_util/ssd_util.cpp
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ssd_util/ssd_util.cpp
index e34c7d56b1b..3ac1ff0ffc0 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/cpp/ssd_util/ssd_util.cpp
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ssd_util/ssd_util.cpp
@@ -241,10 +241,14 @@ void SSDModelUtil::ssd_boxes_decode(const NormalBox *boxes,
float cx = boxes[i].x * scale0 * mDefaultBoxes[i].w + mDefaultBoxes[i].x;
float h = exp(boxes[i].h * scale1) * mDefaultBoxes[i].h;
float w = exp(boxes[i].w * scale1) * mDefaultBoxes[i].w;
- decoded_boxes[i].ymin = std::min(1.0f, std::max(0.0f, cy - h / 2)) * config.model_input_height;
- decoded_boxes[i].xmin = std::min(1.0f, std::max(0.0f, cx - w / 2)) * config.model_input_width;
- decoded_boxes[i].ymax = std::min(1.0f, std::max(0.0f, cy + h / 2)) * config.model_input_height;
- decoded_boxes[i].xmax = std::min(1.0f, std::max(0.0f, cx + w / 2)) * config.model_input_width;
+ decoded_boxes[i].ymin =
+ std::min(1.0f, std::max(0.0f, cy - h / 2)) * config.model_input_height;
+ decoded_boxes[i].xmin =
+ std::min(1.0f, std::max(0.0f, cx - w / 2)) * config.model_input_width;
+ decoded_boxes[i].ymax =
+ std::min(1.0f, std::max(0.0f, cy + h / 2)) * config.model_input_height;
+ decoded_boxes[i].xmax =
+ std::min(1.0f, std::max(0.0f, cx + w / 2)) * config.model_input_width;
}
}
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/cpp/ssd_util/ssd_util.h b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ssd_util/ssd_util.h
similarity index 99%
rename from model_zoo/official/lite/Himindspore/app/src/main/cpp/ssd_util/ssd_util.h
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ssd_util/ssd_util.h
index ad476f622e8..6fe43595146 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/cpp/ssd_util/ssd_util.h
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/cpp/ssd_util/ssd_util.h
@@ -197,4 +197,5 @@ class SSDModelUtil {
{"toothbrush"}
};
};
+
#endif
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/camera/CameraPreview.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/camera/CameraPreview.java
similarity index 97%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/camera/CameraPreview.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/camera/CameraPreview.java
index 067b7f2ca63..05f2aa6d4b2 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/camera/CameraPreview.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/camera/CameraPreview.java
@@ -1,4 +1,19 @@
-package com.mindspore.himindspore.camera;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.camera;
import android.Manifest;
import android.app.Activity;
@@ -37,10 +52,10 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
-import com.mindspore.himindspore.base.TrackListener;
-import com.mindspore.himindspore.imageclassification.help.GarbageTrackingMobile;
-import com.mindspore.himindspore.imageclassification.help.ImageTrackingMobile;
-import com.mindspore.himindspore.objectdetection.help.ObjectTrackingMobile;
+import com.mindspore.imageobject.imageclassification.help.GarbageTrackingMobile;
+import com.mindspore.imageobject.imageclassification.help.ImageTrackingMobile;
+import com.mindspore.imageobject.objectdetection.help.ObjectTrackingMobile;
+import com.mindspore.imageobject.track.TrackListener;
import java.io.File;
import java.io.FileOutputStream;
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/bean/RecognitionImageBean.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/bean/RecognitionImageBean.java
similarity index 94%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/bean/RecognitionImageBean.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/bean/RecognitionImageBean.java
index c7d11074eae..4f003f4542c 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/bean/RecognitionImageBean.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/bean/RecognitionImageBean.java
@@ -13,8 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.mindspore.himindspore.imageclassification.bean;
+package com.mindspore.imageobject.imageclassification.bean;
public class RecognitionImageBean {
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/help/GarbageTrackingMobile.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/help/GarbageTrackingMobile.java
similarity index 94%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/help/GarbageTrackingMobile.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/help/GarbageTrackingMobile.java
index 29c7d21a8cf..553b49cc079 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/help/GarbageTrackingMobile.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/help/GarbageTrackingMobile.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.mindspore.himindspore.imageclassification.help;
+package com.mindspore.imageobject.imageclassification.help;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
-import com.mindspore.himindspore.base.TrackListener;
+import com.mindspore.imageobject.track.TrackListener;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -53,7 +53,7 @@ public class GarbageTrackingMobile implements TrackListener {
* JNI load model and also create model inference environment.
*
* @param modelBuffer Model buffer.
- * @param numThread The num of thread.
+ * @param numThread The num of thread.
* @return MindSpore Inference environment address.
*/
public native long loadModel(ByteBuffer modelBuffer, int numThread);
@@ -62,7 +62,7 @@ public class GarbageTrackingMobile implements TrackListener {
* Running model.
*
* @param netEnv Inference environment address.
- * @param img A picture to be inferred.
+ * @param img A picture to be inferred.
* @return Inference result
*/
public native String runNet(long netEnv, Bitmap img);
@@ -101,6 +101,7 @@ public class GarbageTrackingMobile implements TrackListener {
/**
* Unload model.
+ *
* @return true
*/
public boolean unloadModel() {
@@ -110,6 +111,7 @@ public class GarbageTrackingMobile implements TrackListener {
/**
* Load model file stream.
+ *
* @param modelPath Model file path.
* @return Model ByteBuffer.
*/
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/help/ImageTrackingMobile.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/help/ImageTrackingMobile.java
similarity index 92%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/help/ImageTrackingMobile.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/help/ImageTrackingMobile.java
index 8a1d5efc23b..118bddea80a 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/help/ImageTrackingMobile.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/help/ImageTrackingMobile.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.mindspore.himindspore.imageclassification.help;
+package com.mindspore.imageobject.imageclassification.help;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
-import com.mindspore.himindspore.base.TrackListener;
+import com.mindspore.imageobject.track.TrackListener;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -36,7 +36,7 @@ public class ImageTrackingMobile implements TrackListener {
System.loadLibrary("mlkit-label-MS");
Log.i(TAG, "load libiMindSpore.so successfully.");
} catch (UnsatisfiedLinkError e) {
- Log.e(TAG, "UnsatisfiedLinkError " + e.getMessage());
+ Log.e(TAG, "UnsatisfiedLinkError >>>>>>" + e.getMessage());
}
}
@@ -53,7 +53,7 @@ public class ImageTrackingMobile implements TrackListener {
* JNI load model and also create model inference environment.
*
* @param modelBuffer Model buffer.
- * @param numThread The num of thread.
+ * @param numThread The num of thread.
* @return MindSpore Inference environment address.
*/
public native long loadModel(ByteBuffer modelBuffer, int numThread);
@@ -62,7 +62,7 @@ public class ImageTrackingMobile implements TrackListener {
* Running model.
*
* @param netEnv Inference environment address.
- * @param img A picture to be inferred.
+ * @param img A picture to be inferred.
* @return Inference result
*/
public native String runNet(long netEnv, Bitmap img);
@@ -101,6 +101,7 @@ public class ImageTrackingMobile implements TrackListener {
/**
* Unload model.
+ *
* @return true
*/
public boolean unloadModel() {
@@ -110,6 +111,7 @@ public class ImageTrackingMobile implements TrackListener {
/**
* Load model file stream.
+ *
* @param modelPath Model file path.
* @return Model ByteBuffer.
*/
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/HorTextView.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/ui/HorTextView.java
similarity index 95%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/HorTextView.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/ui/HorTextView.java
index ad7f311d8ef..d1ef733dd94 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/HorTextView.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/ui/HorTextView.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.mindspore.himindspore.imageclassification.ui;
+package com.mindspore.imageobject.imageclassification.ui;
import android.content.Context;
import android.util.AttributeSet;
@@ -25,7 +25,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
-import com.mindspore.himindspore.R;
+import com.mindspore.imageobject.R;
public class HorTextView extends LinearLayout {
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/ImageCameraActivity.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/ui/ImageCameraActivity.java
similarity index 92%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/ImageCameraActivity.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/ui/ImageCameraActivity.java
index be5186e5d32..e5ef8fad664 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/imageclassification/ui/ImageCameraActivity.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/imageclassification/ui/ImageCameraActivity.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.mindspore.himindspore.imageclassification.ui;
+package com.mindspore.imageobject.imageclassification.ui;
import android.graphics.Color;
import android.os.Bundle;
@@ -29,11 +29,14 @@ import android.widget.TextView;
import androidx.annotation.UiThread;
import androidx.appcompat.app.AppCompatActivity;
-import com.mindspore.himindspore.R;
-import com.mindspore.himindspore.camera.CameraPreview;
-import com.mindspore.himindspore.imageclassification.bean.RecognitionImageBean;
-import com.mindspore.himindspore.imageclassification.help.GarbageTrackingMobile;
-import com.mindspore.himindspore.imageclassification.help.ImageTrackingMobile;
+import com.alibaba.android.arouter.facade.annotation.Autowired;
+import com.alibaba.android.arouter.facade.annotation.Route;
+import com.alibaba.android.arouter.launcher.ARouter;
+import com.mindspore.imageobject.R;
+import com.mindspore.imageobject.camera.CameraPreview;
+import com.mindspore.imageobject.imageclassification.bean.RecognitionImageBean;
+import com.mindspore.imageobject.imageclassification.help.GarbageTrackingMobile;
+import com.mindspore.imageobject.imageclassification.help.ImageTrackingMobile;
import java.util.ArrayList;
import java.util.Collections;
@@ -44,13 +47,14 @@ import java.util.List;
* The main interface of camera preview.
* Using Camera 2 API.
*/
+@Route(path = "/imageobject/ImageCameraActivity")
public class ImageCameraActivity extends AppCompatActivity implements CameraPreview.RecognitionDataCallBack {
private static final String TAG = "ImageCameraActivity";
- public static final String OPEN_TYPE = "OPEN_TYPE";
public static final int TYPE_DEMO = 1;
public static final int TYPE_CUSTOM = 2;
- private int enterType;
+ @Autowired(name = "OPEN_TYPE")
+ int enterType;
private LinearLayout bottomLayout;
@@ -65,8 +69,10 @@ public class ImageCameraActivity extends AppCompatActivity implements CameraPrev
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ //inject
+ ARouter.getInstance().inject(this);
+
setContentView(R.layout.activity_image_camera);
- enterType = getIntent().getIntExtra(OPEN_TYPE, TYPE_DEMO);
cameraPreview = findViewById(R.id.image_camera_preview);
bottomLayout = findViewById(R.id.layout_bottom_content);
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/bean/RecognitionObjectBean.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/bean/RecognitionObjectBean.java
similarity index 86%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/bean/RecognitionObjectBean.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/bean/RecognitionObjectBean.java
index bd83cd0f5c7..aa7e717a111 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/bean/RecognitionObjectBean.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/bean/RecognitionObjectBean.java
@@ -1,4 +1,19 @@
-package com.mindspore.himindspore.objectdetection.bean;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.objectdetection.bean;
import android.text.TextUtils;
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/BitmapUtils.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/BitmapUtils.java
new file mode 100644
index 00000000000..bf4d8baf1c3
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/BitmapUtils.java
@@ -0,0 +1,151 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.objectdetection.help;
+
+import android.app.Activity;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Matrix;
+import android.media.ExifInterface;
+import android.net.Uri;
+import android.provider.MediaStore;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BitmapUtils {
+ private static final String TAG = "BitmapUtils";
+
+ public static void recycleBitmap(Bitmap... bitmaps) {
+ for (Bitmap bitmap : bitmaps) {
+ if (bitmap != null && !bitmap.isRecycled()) {
+ bitmap.recycle();
+ bitmap = null;
+ }
+ }
+ }
+
+ private static String getImagePath(Activity activity, Uri uri) {
+ String[] projection = {MediaStore.Images.Media.DATA};
+ Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
+ int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
+ cursor.moveToFirst();
+ return cursor.getString(columnIndex);
+ }
+
+ public static Bitmap loadFromPath(Activity activity, int id, int width, int height) {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ InputStream is = activity.getResources().openRawResource(id);
+ int sampleSize = calculateInSampleSize(options, width, height);
+ options.inSampleSize = sampleSize;
+ options.inJustDecodeBounds = false;
+ return zoomImage(BitmapFactory.decodeStream(is), width, height);
+ }
+
+ public static Bitmap loadFromPath(Activity activity, Uri uri, int width, int height) {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+
+ String path = getImagePath(activity, uri);
+ BitmapFactory.decodeFile(path, options);
+ int sampleSize = calculateInSampleSize(options, width, height);
+ options.inSampleSize = sampleSize;
+ options.inJustDecodeBounds = false;
+
+ Bitmap bitmap = zoomImage(BitmapFactory.decodeFile(path, options), width, height);
+ return rotateBitmap(bitmap, getRotationAngle(path));
+ }
+
+ private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
+ final int width = options.outWidth;
+ final int height = options.outHeight;
+ int inSampleSize = 1;
+
+ if (height > reqHeight || width > reqWidth) {
+ // Calculate height and required height scale.
+ final int heightRatio = Math.round((float) height / (float) reqHeight);
+ // Calculate width and required width scale.
+ final int widthRatio = Math.round((float) width / (float) reqWidth);
+ // Take the larger of the values.
+ inSampleSize = heightRatio > widthRatio ? heightRatio : widthRatio;
+ }
+ return inSampleSize;
+ }
+
+ // Scale pictures to screen width.
+ private static Bitmap zoomImage(Bitmap imageBitmap, int targetWidth, int maxHeight) {
+ float scaleFactor =
+ Math.max(
+ (float) imageBitmap.getWidth() / (float) targetWidth,
+ (float) imageBitmap.getHeight() / (float) maxHeight);
+ Bitmap resizedBitmap =
+ Bitmap.createScaledBitmap(
+ imageBitmap,
+ (int) (imageBitmap.getWidth() / scaleFactor),
+ (int) (imageBitmap.getHeight() / scaleFactor),
+ true);
+
+ return resizedBitmap;
+ }
+
+ /**
+ * Get the rotation angle of the photo.
+ *
+ * @param path photo path.
+ * @return angle.
+ */
+ public static int getRotationAngle(String path) {
+ int rotation = 0;
+ try {
+ ExifInterface exifInterface = new ExifInterface(path);
+ int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
+ switch (orientation) {
+ case ExifInterface.ORIENTATION_ROTATE_90:
+ rotation = 90;
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_180:
+ rotation = 180;
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_270:
+ rotation = 270;
+ break;
+ default:
+ break;
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to get rotation: " + e.getMessage());
+ }
+ return rotation;
+ }
+
+ public static Bitmap rotateBitmap(Bitmap bitmap, int angle) {
+ Matrix matrix = new Matrix();
+ matrix.postRotate(angle);
+ Bitmap result = null;
+ try {
+ result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
+ } catch (OutOfMemoryError e) {
+ Log.e(TAG, "Failed to rotate bitmap: " + e.getMessage());
+ }
+ if (result == null) {
+ return bitmap;
+ }
+ return result;
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/utils/DisplayUtil.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/DisplayUtil.java
similarity index 60%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/utils/DisplayUtil.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/DisplayUtil.java
index 6c01f37ce1c..7612d6762c9 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/utils/DisplayUtil.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/DisplayUtil.java
@@ -1,4 +1,19 @@
-package com.mindspore.himindspore.utils;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.objectdetection.help;
import android.content.Context;
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/help/ObjectTrackingMobile.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/ObjectTrackingMobile.java
similarity index 78%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/help/ObjectTrackingMobile.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/ObjectTrackingMobile.java
index f78fe4219e5..a256300ac72 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/help/ObjectTrackingMobile.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/help/ObjectTrackingMobile.java
@@ -1,11 +1,26 @@
-package com.mindspore.himindspore.objectdetection.help;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.objectdetection.help;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.util.Log;
-import com.mindspore.himindspore.base.TrackListener;
+import com.mindspore.imageobject.track.TrackListener;
import java.io.FileNotFoundException;
import java.io.InputStream;
@@ -20,7 +35,7 @@ public class ObjectTrackingMobile implements TrackListener {
System.loadLibrary("mlkit-label-MS");
Log.i(TAG, "load libiMindSpore.so successfully.");
} catch (UnsatisfiedLinkError e) {
- Log.e(TAG, "UnsatisfiedLinkError " + e.getMessage());
+ Log.e(TAG, "UnsatisfiedLinkError >>>>>>" + e.getMessage());
}
}
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectCameraActivity.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectCameraActivity.java
similarity index 66%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectCameraActivity.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectCameraActivity.java
index eb68aa11a30..77c50ad29bc 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectCameraActivity.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectCameraActivity.java
@@ -1,4 +1,19 @@
-package com.mindspore.himindspore.objectdetection.ui;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.objectdetection.ui;
import android.os.Bundle;
import android.text.TextUtils;
@@ -6,15 +21,16 @@ import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
-import com.mindspore.himindspore.R;
-import com.mindspore.himindspore.camera.CameraPreview;
-import com.mindspore.himindspore.objectdetection.bean.RecognitionObjectBean;
-import com.mindspore.himindspore.objectdetection.help.ObjectTrackingMobile;
+import com.alibaba.android.arouter.facade.annotation.Route;
+import com.mindspore.imageobject.R;
+import com.mindspore.imageobject.camera.CameraPreview;
+import com.mindspore.imageobject.objectdetection.bean.RecognitionObjectBean;
+import com.mindspore.imageobject.objectdetection.help.ObjectTrackingMobile;
import java.io.FileNotFoundException;
import java.util.List;
-import static com.mindspore.himindspore.objectdetection.bean.RecognitionObjectBean.getRecognitionList;
+import static com.mindspore.imageobject.objectdetection.bean.RecognitionObjectBean.getRecognitionList;
/**
@@ -22,7 +38,7 @@ import static com.mindspore.himindspore.objectdetection.bean.RecognitionObjectBe
*
* Pass in pictures to JNI, test mindspore model, load reasoning, etc
*/
-
+@Route(path = "/imageobject/ObjectCameraActivity")
public class ObjectCameraActivity extends AppCompatActivity implements CameraPreview.RecognitionDataCallBack {
private final String TAG = "ObjectCameraActivity";
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectPhotoActivity.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectPhotoActivity.java
similarity index 85%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectPhotoActivity.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectPhotoActivity.java
index 16da11edbf7..d64d883a148 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectPhotoActivity.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectPhotoActivity.java
@@ -1,4 +1,19 @@
-package com.mindspore.himindspore.objectdetection.ui;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.objectdetection.ui;
import android.content.Intent;
import android.content.res.Configuration;
@@ -17,18 +32,19 @@ import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
-import com.mindspore.himindspore.R;
-import com.mindspore.himindspore.objectdetection.bean.RecognitionObjectBean;
-import com.mindspore.himindspore.objectdetection.help.BitmapUtils;
-import com.mindspore.himindspore.objectdetection.help.ObjectTrackingMobile;
-import com.mindspore.himindspore.utils.DisplayUtil;
+import com.alibaba.android.arouter.facade.annotation.Route;
+import com.mindspore.imageobject.R;
+import com.mindspore.imageobject.objectdetection.bean.RecognitionObjectBean;
+import com.mindspore.imageobject.objectdetection.help.BitmapUtils;
+import com.mindspore.imageobject.objectdetection.help.DisplayUtil;
+import com.mindspore.imageobject.objectdetection.help.ObjectTrackingMobile;
import java.io.FileNotFoundException;
import java.util.List;
-import static com.mindspore.himindspore.objectdetection.bean.RecognitionObjectBean.getRecognitionList;
-
+import static com.mindspore.imageobject.objectdetection.bean.RecognitionObjectBean.getRecognitionList;
+@Route(path = "/imageobject/ObjectPhotoActivity")
public class ObjectPhotoActivity extends AppCompatActivity {
private static final String TAG = "ObjectPhotoActivity";
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectRectView.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectRectView.java
similarity index 78%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectRectView.java
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectRectView.java
index af7f4282c04..b5182295abc 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/ui/ObjectRectView.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectRectView.java
@@ -1,4 +1,19 @@
-package com.mindspore.himindspore.objectdetection.ui;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.objectdetection.ui;
import android.content.Context;
import android.graphics.Canvas;
@@ -9,9 +24,9 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
-import com.mindspore.himindspore.R;
-import com.mindspore.himindspore.objectdetection.bean.RecognitionObjectBean;
-import com.mindspore.himindspore.utils.DisplayUtil;
+import com.mindspore.imageobject.R;
+import com.mindspore.imageobject.objectdetection.bean.RecognitionObjectBean;
+import com.mindspore.imageobject.objectdetection.help.DisplayUtil;
import java.util.ArrayList;
import java.util.List;
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/track/TrackListener.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/track/TrackListener.java
new file mode 100644
index 00000000000..f3a3734ff42
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/track/TrackListener.java
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.imageobject.track;
+
+public interface TrackListener {
+}
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-v24/ic_launcher_foreground.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 00000000000..2b068d11462
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-v24/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-xxhdpi/logo.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-xxhdpi/logo.png
new file mode 100644
index 00000000000..4dd2da3ecb2
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-xxhdpi/logo.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-xxhdpi/logo2.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-xxhdpi/logo2.png
new file mode 100644
index 00000000000..c90f1dda439
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable-xxhdpi/logo2.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable/ic_launcher_background.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 00000000000..07d5da9cbf1
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_image_camera.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/activity_image_camera.xml
similarity index 90%
rename from model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_image_camera.xml
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/activity_image_camera.xml
index b53ac36ea03..fd6eb2a6096 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_image_camera.xml
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/activity_image_camera.xml
@@ -5,10 +5,10 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".imageclassification.ui.ImageCameraActivity">
+ tools:context="com.mindspore.imageobject.imageclassification.ui.ImageCameraActivity">
-
-
+ tools:context="com.mindspore.imageobject.objectdetection.ui.ObjectCameraActivity">
-
-
-
+ android:layout_height="match_parent" />
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_object_photo.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/activity_object_photo.xml
similarity index 56%
rename from model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_object_photo.xml
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/activity_object_photo.xml
index f029ddc500d..2e2b5f4da74 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/activity_object_photo.xml
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/activity_object_photo.xml
@@ -7,10 +7,10 @@
android:keepScreenOn="true"
android:orientation="vertical">
-
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/layout_hor_text_view.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/layout_hor_text_view.xml
similarity index 96%
rename from model_zoo/official/lite/Himindspore/app/src/main/res/layout/layout_hor_text_view.xml
rename to model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/layout_hor_text_view.xml
index 12dcef2ba2b..89323fb9788 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/res/layout/layout_hor_text_view.xml
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/layout/layout_hor_text_view.xml
@@ -39,5 +39,5 @@
android:background="@color/white"
android:layout_below="@+id/tv_left_title"
android:layout_height="0.5dp"
- android:layout_width="match_parent"/>
+ android:layout_width="match_parent" />
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-hdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 00000000000..2664a232081
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-hdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..4ca0c30a5a1
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-mdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 00000000000..d9667b92afe
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-mdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..a5e2dc1825c
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xhdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 00000000000..430c40fefde
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..cf939c9f1d2
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxhdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 00000000000..9347fb2a8af
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..c184f7de73f
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 00000000000..22ca1a84b36
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..6bca5825c39
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/colors.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/colors.xml
new file mode 100644
index 00000000000..b5609727e1b
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/colors.xml
@@ -0,0 +1,20 @@
+
+
+ #303030
+ #3700B3
+ #03DAC5
+
+ #66000000
+
+ #ffffff
+ #000000
+ #A69D9D
+ #424242
+
+ #6DA7FF
+ #F8E71C
+ #FF844D
+ #66B50A
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/dimens.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/dimens.xml
new file mode 100644
index 00000000000..df6eaa6523f
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/dimens.xml
@@ -0,0 +1,9 @@
+
+
+ 15dp
+ 8dp
+
+ 15dp
+ 6dp
+ 14sp
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/strings.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/strings.xml
new file mode 100644
index 00000000000..69bc2200ca7
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/strings.xml
@@ -0,0 +1,23 @@
+
+ HiMindSpore
+ MindSpore
+ custom
+
+ Image Classification
+ Garbage Classification
+ Photo Detection
+ Camera Detection
+ PoseNet
+ Style Transfer
+ Source Code
+ Help And FeedBack
+
+ Photo
+ Camera
+
+ Demo
+ Custom
+
+ Inference Time
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/styles.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/styles.xml
new file mode 100644
index 00000000000..d9b3e2990fb
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/values/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/res/xml/file_paths.xml b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/xml/file_paths.xml
new file mode 100644
index 00000000000..1d21aa9902b
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/res/xml/file_paths.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/test/java/com/mindspore/imageobject/ExampleUnitTest.java b/model_zoo/official/lite/Himindspore/imageObject/src/test/java/com/mindspore/imageobject/ExampleUnitTest.java
new file mode 100644
index 00000000000..75c30bc3a18
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/test/java/com/mindspore/imageobject/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.mindspore.imageobject;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/.gitignore b/model_zoo/official/lite/Himindspore/posenet/.gitignore
new file mode 100644
index 00000000000..42afabfd2ab
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/build.gradle b/model_zoo/official/lite/Himindspore/posenet/build.gradle
new file mode 100644
index 00000000000..8e97f92ab6f
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/build.gradle
@@ -0,0 +1,71 @@
+plugins {
+ id 'com.android.library'
+}
+
+android {
+ compileSdkVersion 30
+ buildToolsVersion "30.0.1"
+
+ defaultConfig {
+ minSdkVersion 21
+ targetSdkVersion 30
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ javaCompileOptions {
+ annotationProcessorOptions {
+ arguments = [moduleName: project.getName()]
+ }
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ aaptOptions {
+ noCompress "ms"
+ }
+
+ lintOptions {
+ checkReleaseBuilds false
+ // Or, if you prefer, you can continue to check for errors in release builds,
+ // but continue the build even when errors are found:
+ abortOnError false
+ }
+
+ repositories {
+ google()
+ jcenter()
+ flatDir {
+ dirs 'libs'
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+}
+
+// Download default models; if you wish to use your own models then
+// place them in the "assets" directory and comment out this line.
+apply from: 'download.gradle'
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
+ implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'com.google.android.material:material:1.2.1'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
+ testImplementation 'junit:junit:4.+'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.2'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
+
+ implementation 'com.alibaba:arouter-api:1.2.1'
+ annotationProcessor 'com.alibaba:arouter-compiler:1.1.2'
+
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/download.gradle b/model_zoo/official/lite/Himindspore/posenet/download.gradle
new file mode 100644
index 00000000000..ef3a3ced0d9
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/download.gradle
@@ -0,0 +1,73 @@
+/**
+ * To download necessary library from HuaWei server.
+ * Including mindspore-lite .so file, minddata-lite .so file and model file.
+ * The libraries can be downloaded manually.
+ */
+def mindsporeLite_Version = "mindspore-lite-maven-1.0.1"
+def targetModelFile = "src/main/assets/posenet_model.ms"
+def modelDownloadUrl = "https://download.mindspore.cn/model_zoo/official/lite/posenet_lite/posenet_model.ms"
+def mindsporeLiteDownloadUrl = "https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.0.1/lite/java/${mindsporeLite_Version}.zip"
+def mindSporeLibrary = "libs/${mindsporeLite_Version}.zip"
+def cleantargetMindSporeInclude = "libs"
+def targetMindSporeInclude = "libs/"
+
+
+task downloadModelFile(type: DownloadUrlTask) {
+ doFirst {
+ println "Downloading ${modelDownloadUrl}"
+ }
+ sourceUrl = "${modelDownloadUrl}"
+ target = file("${targetModelFile}")
+}
+
+
+task downloadMindSporeLibrary(type: DownloadUrlTask) {
+ doFirst {
+ println "Downloading ${mindsporeLiteDownloadUrl}"
+ }
+ sourceUrl = "${mindsporeLiteDownloadUrl}"
+ target = file("${mindSporeLibrary}")
+}
+
+task unzipMindSporeInclude(type: Copy, dependsOn: ['downloadMindSporeLibrary']) {
+ doFirst {
+ println "Unzipping ${mindSporeLibrary}"
+ }
+ from zipTree("${mindSporeLibrary}")
+ into "${targetMindSporeInclude}"
+}
+
+task cleanUnusedmindsporeFiles(type: Delete, dependsOn: ['unzipMindSporeInclude']) {
+ delete fileTree("${cleantargetMindSporeInclude}").matching {
+ include "*.zip"
+ }
+}
+
+if (file("libs/mindspore-lite-1.0.1.aar").exists()) {
+ downloadMindSporeLibrary.enabled = false
+ unzipMindSporeInclude.enabled = false
+ cleanUnusedmindsporeFiles.enabled = false
+}
+
+
+if (file("src/main/assets/posenet_model.ms").exists()) {
+ downloadModelFile.enabled = false
+}
+
+preBuild.dependsOn downloadModelFile
+preBuild.dependsOn downloadMindSporeLibrary
+preBuild.dependsOn unzipMindSporeInclude
+preBuild.dependsOn cleanUnusedmindsporeFiles
+
+class DownloadUrlTask extends DefaultTask {
+ @Input
+ String sourceUrl
+
+ @OutputFile
+ File target
+
+ @TaskAction
+ void download() {
+ ant.get(src: sourceUrl, dest: target)
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/posenet/proguard-rules.pro b/model_zoo/official/lite/Himindspore/posenet/proguard-rules.pro
new file mode 100644
index 00000000000..481bb434814
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/androidTest/java/com/mindspore/posenet/ExampleInstrumentedTest.java b/model_zoo/official/lite/Himindspore/posenet/src/androidTest/java/com/mindspore/posenet/ExampleInstrumentedTest.java
new file mode 100644
index 00000000000..03b8be7651e
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/androidTest/java/com/mindspore/posenet/ExampleInstrumentedTest.java
@@ -0,0 +1,26 @@
+package com.mindspore.posenet;
+
+import android.content.Context;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ assertEquals("com.mindspore.posenet", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/AndroidManifest.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/AndroidManifest.xml
new file mode 100644
index 00000000000..55e81c33b52
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/AndroidManifest.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/CameraDataDealListener.java b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/CameraDataDealListener.java
new file mode 100644
index 00000000000..ec359100f5d
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/CameraDataDealListener.java
@@ -0,0 +1,23 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.posenet;
+
+import android.media.Image;
+import android.view.SurfaceView;
+
+public interface CameraDataDealListener {
+ void dataDeal(Image image, SurfaceView surfaceView);
+}
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/ImageUtils.java b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/ImageUtils.java
new file mode 100644
index 00000000000..193b741380c
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/ImageUtils.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.posenet;
+
+public class ImageUtils {
+ // This value is 2 ^ 18 - 1, and is used to hold the RGB values together before their ranges
+ // are normalized to eight bits.
+ private static final int MAX_CHANNEL_VALUE = 262143;
+
+ /**
+ * Helper function to convert y,u,v integer values to RGB format
+ */
+ private static int convertYUVToRGB(int y, int u, int v) {
+ // Adjust and check YUV values
+ int yNew = y - 16 < 0 ? 0 : y - 16;
+ int uNew = u - 128;
+ int vNew = v - 128;
+ int expandY = 1192 * yNew;
+ int r = checkBoundaries(expandY + 1634 * vNew);
+ int g = checkBoundaries(expandY - 833 * vNew - 400 * uNew);
+ int b = checkBoundaries(expandY + 2066 * uNew);
+
+ return -0x1000000 | (r << 6 & 0xff0000) | (g >> 2 & 0xff00) | (b >> 10 & 0xff);
+ }
+
+
+ private static int checkBoundaries(int value) {
+ if (value > MAX_CHANNEL_VALUE) {
+ return MAX_CHANNEL_VALUE;
+ } else if (value < 0) {
+ return 0;
+ } else {
+ return value;
+ }
+ }
+
+ /**
+ * Converts YUV420 format image data (ByteArray) into ARGB8888 format with IntArray as output.
+ */
+ public static void convertYUV420ToARGB8888(byte[] yData, byte[] uData, byte[] vData,
+ int width, int height,
+ int yRowStride, int uvRowStride, int uvPixelStride, int[] out) {
+
+ int outputIndex = 0;
+ for (int j = 0; j < height; j++) {
+ int positionY = yRowStride * j;
+ int positionUV = uvRowStride * (j >> 1);
+
+ for (int i = 0; i < width; i++) {
+ int uvOffset = positionUV + (i >> 1) * uvPixelStride;
+
+ // "0xff and" is used to cut off bits from following value that are higher than
+ // the low 8 bits
+ out[outputIndex++] = convertYUVToRGB(
+ 0xff & yData[positionY + i], 0xff & uData[uvOffset],
+ 0xff & vData[uvOffset]);
+
+ }
+ }
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PoseNetFragment.java b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PoseNetFragment.java
new file mode 100644
index 00000000000..92ae9546d1d
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PoseNetFragment.java
@@ -0,0 +1,390 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.posenet;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.ImageFormat;
+import android.hardware.camera2.CameraAccessException;
+import android.hardware.camera2.CameraCaptureSession;
+import android.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CameraDevice;
+import android.hardware.camera2.CameraManager;
+import android.hardware.camera2.CaptureRequest;
+import android.hardware.camera2.CaptureResult;
+import android.hardware.camera2.TotalCaptureResult;
+import android.media.Image;
+import android.media.ImageReader;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.util.Log;
+import android.util.Size;
+import android.view.LayoutInflater;
+import android.view.Surface;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.core.app.ActivityCompat;
+import androidx.fragment.app.Fragment;
+
+import java.util.Arrays;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * create an instance of this fragment.
+ */
+public class PoseNetFragment extends Fragment {
+
+ private final static int REQUEST_CAMERA_PERMISSION = 1;
+ private String cameraId = "1";
+ private SurfaceView surfaceView;
+ private CameraCaptureSession captureSession;
+ private CameraDevice cameraDevice;
+ private Size previewSize;
+ private int previewWidth;
+ private int previewHeight;
+ private final int PREVIEW_WIDTH = 640;
+ private final int PREVIEW_HEIGHT = 480;
+ private HandlerThread backgroundThread;
+ private Handler backgroundHandler;
+ private ImageReader imageReader;
+ private CaptureRequest.Builder previewRequestBuilder;
+ private CaptureRequest previewRequest;
+ private Semaphore cameraOpenCloseLock = new Semaphore(1);//使用信号量 Semaphore 进行多线程任务调度
+ private boolean flashSupported;
+
+
+ private static final String TAG = "PoseNetFragment";
+
+ private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
+
+ @Override
+ public void onOpened(@NonNull CameraDevice mCameraDevice) {
+ cameraOpenCloseLock.release();
+ Log.d(TAG, "camera has open");
+ PoseNetFragment.this.cameraDevice = mCameraDevice;
+ createCameraPreviewSession();
+ }
+
+ @Override
+ public void onDisconnected(@NonNull CameraDevice cameraDevice) {
+ cameraOpenCloseLock.release();
+ cameraDevice.close();
+ PoseNetFragment.this.cameraDevice = null;
+ }
+
+ @Override
+ public void onError(@NonNull CameraDevice cameraDevice, int error) {
+ onDisconnected(cameraDevice);
+ Activity activity = getActivity();
+ if (activity != null) {
+ activity.finish();
+ }
+ }
+ };
+
+
+ private CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
+ @Override
+ public void onCaptureProgressed(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull CaptureResult partialResult) {
+ super.onCaptureProgressed(session, request, partialResult);
+ }
+
+ @Override
+ public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
+ super.onCaptureCompleted(session, request, result);
+ }
+ };
+
+ private CameraDataDealListener cameraDataDealListener;
+
+ public void setCameraDataDealListener(CameraDataDealListener cameraDataDealListener) {
+ this.cameraDataDealListener = cameraDataDealListener;
+ }
+
+ public static PoseNetFragment newInstance() {
+ PoseNetFragment fragment = new PoseNetFragment();
+ return fragment;
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_pose_net, container, false);
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ this.surfaceView = view.findViewById(R.id.surfaceView);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ startBackgroundThread();
+ }
+
+ public void onStart() {
+ super.onStart();
+ openCamera();
+ }
+
+ public void onPause() {
+ this.closeCamera();
+ this.stopBackgroundThread();
+ super.onPause();
+ }
+
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ private void requestCameraPermission() {
+ if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
+ Toast.makeText(getContext(), "This app needs camera permission.", Toast.LENGTH_LONG).show();
+ } else {
+ requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ if (requestCode == REQUEST_CAMERA_PERMISSION) {
+ if (allPermissionsGranted(grantResults)) {
+ Toast.makeText(getContext(), "This app needs camera permission.", Toast.LENGTH_LONG).show();
+ }
+ } else {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+ }
+
+ private boolean allPermissionsGranted(int[] grantResults) {
+ for (int grantResult : grantResults) {
+ if (grantResult == PackageManager.PERMISSION_DENIED) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Sets up member variables related to camera.
+ */
+ private void setUpCameraOutputs() {
+ CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
+ try {
+ for (String cameraId : manager.getCameraIdList()) {
+ CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
+ // We don't use a front facing camera in this sample.
+ Integer cameraDirection = characteristics.get(CameraCharacteristics.LENS_FACING);
+ if (cameraDirection != null && cameraDirection == CameraCharacteristics.LENS_FACING_FRONT) {
+ continue;
+ }
+
+ previewSize = new Size(PREVIEW_WIDTH, PREVIEW_HEIGHT);
+
+ imageReader = ImageReader.newInstance(
+ PREVIEW_WIDTH, PREVIEW_HEIGHT,
+ ImageFormat.YUV_420_888, /*maxImages*/ 2
+ );
+
+ previewHeight = previewSize.getHeight();
+ previewWidth = previewSize.getWidth();
+ // Initialize the storage bitmaps once when the resolution is known.
+
+ // Check if the flash is supported.
+ flashSupported =
+ characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE) == true;
+
+ this.cameraId = cameraId;
+
+ // We've found a viable camera and finished setting up member variables,
+ // so we don't need to iterate through other available cameras.
+ return;
+ }
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Opens the camera specified by [PosenetActivity.cameraId].
+ */
+ @SuppressLint("MissingPermission")
+ private void openCamera() {
+ if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
+ this.requestCameraPermission();
+ }
+ setUpCameraOutputs();
+ CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
+ try {
+ // Wait for camera to open - 2.5 seconds is sufficient
+ if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
+ throw new RuntimeException("Time out waiting to lock camera opening.");
+ }
+ manager.openCamera(cameraId, mStateCallback, backgroundHandler);
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void closeCamera() {
+ try {
+ cameraOpenCloseLock.acquire();
+ if (captureSession != null) {
+ captureSession.close();
+ captureSession = null;
+ }
+ if (null != cameraDevice) {
+ cameraDevice.close();
+ cameraDevice = null;
+ }
+ if (null != imageReader) {
+ imageReader.close();
+ imageReader = null;
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted while trying to lock camera closing.", e);
+ } finally {
+ cameraOpenCloseLock.release();
+ }
+ }
+
+ /**
+ * Starts a background thread and its [Handler].
+ */
+ private void startBackgroundThread() {
+ backgroundThread = new HandlerThread("imageAvailableListener");
+ backgroundThread.start();
+ backgroundHandler = new Handler(backgroundThread.getLooper());
+ }
+
+ /**
+ * Stops the background thread and its [Handler].
+ */
+ private void stopBackgroundThread() {
+ backgroundThread.quitSafely();
+ try {
+ backgroundThread.join();
+ backgroundThread = null;
+ backgroundHandler = null;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ private final ImageReader.OnImageAvailableListener imageAvailableListener = new ImageReader.OnImageAvailableListener() {
+ @Override
+ public void onImageAvailable(ImageReader imageReader) {
+ if (previewWidth != 0 && previewHeight != 0 && imageReader != null) {
+ Image image = imageReader.acquireLatestImage();
+
+ if (cameraDataDealListener != null) {
+ cameraDataDealListener.dataDeal(image, surfaceView);
+ }
+ }
+ }
+ };
+
+
+ /**
+ * Creates a new [CameraCaptureSession] for camera preview.
+ */
+ private void createCameraPreviewSession() {
+ try {
+ // We capture images from preview in YUV format.
+ imageReader = ImageReader.newInstance(
+ previewSize.getWidth(), previewSize.getHeight(), ImageFormat.YUV_420_888, 2);
+ imageReader.setOnImageAvailableListener(imageAvailableListener, backgroundHandler);
+
+ // This is the surface we need to record images for processing.
+ Surface recordingSurface = imageReader.getSurface();
+
+ // We set up a CaptureRequest.Builder with the output Surface.
+ previewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
+ previewRequestBuilder.addTarget(recordingSurface);
+
+ // Here, we create a CameraCaptureSession for camera preview.
+ cameraDevice.createCaptureSession(
+ Arrays.asList(recordingSurface),
+ new CameraCaptureSession.StateCallback() {
+ @Override
+ public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
+ // The camera is already closed
+ if (cameraDevice == null) {
+ return;
+ }
+
+ // When the session is ready, we start displaying the preview.
+ captureSession = cameraCaptureSession;
+ try {
+ // Auto focus should be continuous for camera preview.
+ previewRequestBuilder.set(
+ CaptureRequest.CONTROL_AF_MODE,
+ CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
+ );
+ // Flash is automatically enabled when necessary.
+ setAutoFlash(previewRequestBuilder);
+
+ // Finally, we start displaying the camera preview.
+ previewRequest = previewRequestBuilder.build();
+ captureSession.setRepeatingRequest(
+ previewRequest,
+ captureCallback, backgroundHandler);
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
+ }
+ },
+ null);
+ } catch (CameraAccessException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
+
+ private void setAutoFlash(CaptureRequest.Builder requestBuilder) {
+ if (flashSupported) {
+ requestBuilder.set(
+ CaptureRequest.CONTROL_AE_MODE,
+ CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/Posenet.java b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/Posenet.java
new file mode 100644
index 00000000000..e43fe3e4b25
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/Posenet.java
@@ -0,0 +1,315 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.posenet;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.os.SystemClock;
+import android.util.Log;
+
+import androidx.core.util.Pair;
+
+import com.mindspore.lite.LiteSession;
+import com.mindspore.lite.MSTensor;
+import com.mindspore.lite.Model;
+import com.mindspore.lite.config.CpuBindMode;
+import com.mindspore.lite.config.DeviceType;
+import com.mindspore.lite.config.MSConfig;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import static java.lang.Math.exp;
+
+public class Posenet {
+
+ public enum BodyPart {
+ NOSE,
+ LEFT_EYE,
+ RIGHT_EYE,
+ LEFT_EAR,
+ RIGHT_EAR,
+ LEFT_SHOULDER,
+ RIGHT_SHOULDER,
+ LEFT_ELBOW,
+ RIGHT_ELBOW,
+ LEFT_WRIST,
+ RIGHT_WRIST,
+ LEFT_HIP,
+ RIGHT_HIP,
+ LEFT_KNEE,
+ RIGHT_KNEE,
+ LEFT_ANKLE,
+ RIGHT_ANKLE
+ }
+
+ public class Position {
+ int x;
+ int y;
+ }
+
+ public class KeyPoint {
+ BodyPart bodyPart = BodyPart.NOSE;
+ Position position = new Position();
+ float score = 0.0f;
+ }
+
+ public class Person {
+ List keyPoints;
+ float score = 0.0f;
+ }
+
+ private Context mContext;
+
+ private MSConfig msConfig;
+ private LiteSession session;
+ private Model model;
+ private LinkedHashMap mOutputs;
+
+
+ public long lastInferenceTimeNanos;
+ private final int NUM_THREADS = 4;
+
+ public Posenet(Context context) {
+ mContext = context;
+ init();
+ }
+
+ public boolean init() {
+ // Load the .ms model.
+ model = new Model();
+ if (!model.loadModel(mContext, "posenet_model.ms")) {
+ Log.e("MS_LITE", "Load Model failed");
+ return false;
+ }
+
+ // Create and init config.
+ msConfig = new MSConfig();
+ if (!msConfig.init(DeviceType.DT_CPU, NUM_THREADS, CpuBindMode.MID_CPU)) {
+ Log.e("MS_LITE", "Init context failed");
+ return false;
+ }
+
+ // Create the MindSpore lite session.
+ session = new LiteSession();
+ if (!session.init(msConfig)) {
+ Log.e("MS_LITE", "Create session failed");
+ msConfig.free();
+ return false;
+ }
+ msConfig.free();
+
+ // Complile 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.
+ model.freeBuffer();
+
+ return true;
+ }
+
+
+ private float sigmoid(float x) {
+ return (float) (1.0f / (1.0f + exp(-x)));
+ }
+
+ /**
+ * Scale the image to a byteBuffer of [-1,1] values.
+ */
+ private ByteBuffer initInputArray(Bitmap bitmap) {
+ final int bytesPerChannel = 4;
+ final int inputChannels = 3;
+ final int batchSize = 1;
+ ByteBuffer inputBuffer = ByteBuffer.allocateDirect(
+ batchSize * bytesPerChannel * bitmap.getHeight() * bitmap.getWidth() * inputChannels
+ );
+ inputBuffer.order(ByteOrder.nativeOrder());
+ inputBuffer.rewind();
+
+ final float mean = 128.0f;
+ final float std = 128.0f;
+ int[] intValues = new int[bitmap.getWidth() * bitmap.getHeight()];
+ bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
+
+
+ int pixel = 0;
+ for (int y = 0; y < bitmap.getHeight(); y++) {
+ for (int x = 0; x < bitmap.getWidth(); x++) {
+ int value = intValues[pixel++];
+ inputBuffer.putFloat(((float) (value >> 16 & 0xFF) - mean) / std);
+ inputBuffer.putFloat(((float) (value >> 8 & 0xFF) - mean) / std);
+ inputBuffer.putFloat(((float) (value & 0xFF) - mean) / std);
+ }
+ }
+ return inputBuffer;
+ }
+
+
+ /**
+ * Estimates the pose for a single person.
+ * args:
+ * bitmap: image bitmap of frame that should be processed
+ * returns:
+ * person: a Person object containing data about keypoint locations and confidence scores
+ */
+ Person estimateSinglePose(Bitmap bitmap) {
+ long estimationStartTimeNanos = SystemClock.elapsedRealtimeNanos();
+ ByteBuffer inputArray = this.initInputArray(bitmap);
+ List inputs = session.getInputs();
+ if (inputs.size() != 1) {
+ return null;
+ }
+
+ Log.i("posenet", String.format("Scaling to [-1,1] took %.2f ms",
+ 1.0f * (SystemClock.elapsedRealtimeNanos() - estimationStartTimeNanos) / 1_000_000));
+
+ MSTensor inTensor = inputs.get(0);
+ inTensor.setData(inputArray);
+ long inferenceStartTimeNanos = SystemClock.elapsedRealtimeNanos();
+
+ // Run graph to infer results.
+ if (!session.runGraph()) {
+ Log.e("MS_LITE", "Run graph failed");
+ return null;
+ }
+
+ lastInferenceTimeNanos = SystemClock.elapsedRealtimeNanos() - inferenceStartTimeNanos;
+ Log.i(
+ "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) {
+ 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
+ int numKeypoints = heatmaps[0][0][0].length; //17
+
+ // Finds the (row, col) locations of where the keypoints are most likely to be.
+ Pair[] keypointPositions = new Pair[numKeypoints];
+ for (int i = 0; i < numKeypoints; i++) {
+ keypointPositions[i] = new Pair(0, 0);
+ }
+
+ for (int keypoint = 0; keypoint < numKeypoints; keypoint++) {
+ float maxVal = heatmaps[0][0][0][keypoint];
+ int maxRow = 0;
+ int maxCol = 0;
+ for (int row = 0; row < height; row++) {
+ for (int col = 0; col < width; col++) {
+ if (heatmaps[0][row][col][keypoint] > maxVal) {
+ maxVal = heatmaps[0][row][col][keypoint];
+ maxRow = row;
+ maxCol = col;
+ }
+ }
+ }
+ keypointPositions[keypoint] = new Pair(maxRow, maxCol);
+ }
+
+ // Calculating the x and y coordinates of the keypoints with offset adjustment.
+ int[] xCoords = new int[numKeypoints];
+ int[] yCoords = new int[numKeypoints];
+ float[] confidenceScores = new float[numKeypoints];
+ for (int i = 0; i < keypointPositions.length; i++) {
+ Pair position = keypointPositions[i];
+ int positionY = (int) position.first;
+ int positionX = (int) position.second;
+
+ yCoords[i] = (int) ((float) positionY / (float) (height - 1) * bitmap.getHeight() + offsets[0][positionY][positionX][i]);
+ xCoords[i] = (int) ((float) positionX / (float) (width - 1) * bitmap.getWidth() + offsets[0][positionY][positionX][i + numKeypoints]);
+ confidenceScores[i] = sigmoid(heatmaps[0][positionY][positionX][i]);
+ }
+
+ Person person = new Person();
+ KeyPoint[] keypointList = new KeyPoint[numKeypoints];
+ for (int i = 0; i < numKeypoints; i++) {
+ keypointList[i] = new KeyPoint();
+ }
+
+ float totalScore = 0.0f;
+ for (int i = 0; i < keypointList.length; i++) {
+ keypointList[i].position.x = xCoords[i];
+ keypointList[i].position.y = yCoords[i];
+ keypointList[i].score = confidenceScores[i];
+ totalScore += confidenceScores[i];
+ }
+ person.keyPoints = Arrays.asList(keypointList);
+ person.score = totalScore / numKeypoints;
+
+ return person;
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java
new file mode 100644
index 00000000000..7f79885c95c
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java
@@ -0,0 +1,265 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.posenet;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.Rect;
+import android.hardware.camera2.CameraCharacteristics;
+import android.media.Image;
+import android.os.Bundle;
+import android.view.SurfaceView;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.util.Pair;
+
+import com.alibaba.android.arouter.facade.annotation.Route;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
+
+import static com.mindspore.posenet.Posenet.BodyPart.LEFT_ANKLE;
+import static com.mindspore.posenet.Posenet.BodyPart.LEFT_ELBOW;
+import static com.mindspore.posenet.Posenet.BodyPart.LEFT_HIP;
+import static com.mindspore.posenet.Posenet.BodyPart.LEFT_KNEE;
+import static com.mindspore.posenet.Posenet.BodyPart.LEFT_SHOULDER;
+import static com.mindspore.posenet.Posenet.BodyPart.LEFT_WRIST;
+import static com.mindspore.posenet.Posenet.BodyPart.RIGHT_ANKLE;
+import static com.mindspore.posenet.Posenet.BodyPart.RIGHT_ELBOW;
+import static com.mindspore.posenet.Posenet.BodyPart.RIGHT_HIP;
+import static com.mindspore.posenet.Posenet.BodyPart.RIGHT_KNEE;
+import static com.mindspore.posenet.Posenet.BodyPart.RIGHT_SHOULDER;
+import static com.mindspore.posenet.Posenet.BodyPart.RIGHT_WRIST;
+
+@Route(path = "/posenet/PosenetMainActivity")
+public class PosenetMainActivity extends AppCompatActivity implements CameraDataDealListener {
+
+ private final List bodyJoints;
+
+
+ /**
+ * Model input shape for images.
+ */
+ private final static int MODEL_WIDTH = 257;
+ private final static int MODEL_HEIGHT = 257;
+
+ private final double minConfidence = 0.5;
+ private final float circleRadius = 8.0f;
+ private Paint paint = new Paint();
+ private final int PREVIEW_WIDTH = 640;
+ private final int PREVIEW_HEIGHT = 480;
+ private Posenet posenet;
+ private int[] rgbBytes = new int[PREVIEW_WIDTH * PREVIEW_HEIGHT];
+ private byte[][] yuvBytes = new byte[3][];
+ private SurfaceView surfaceView;
+
+ private int lensFacing = CameraCharacteristics.LENS_FACING_BACK;
+ private PoseNetFragment poseNetFragment;
+
+ public PosenetMainActivity() {
+ bodyJoints = Arrays.asList(
+ new Pair(LEFT_WRIST, LEFT_ELBOW), new Pair(LEFT_ELBOW, LEFT_SHOULDER),
+ new Pair(LEFT_SHOULDER, RIGHT_SHOULDER), new Pair(RIGHT_SHOULDER, RIGHT_ELBOW),
+ new Pair(RIGHT_ELBOW, RIGHT_WRIST), new Pair(LEFT_SHOULDER, LEFT_HIP),
+ new Pair(LEFT_HIP, RIGHT_HIP), new Pair(RIGHT_HIP, RIGHT_SHOULDER),
+ new Pair(LEFT_HIP, LEFT_KNEE), new Pair(LEFT_KNEE, LEFT_ANKLE),
+ new Pair(RIGHT_HIP, RIGHT_KNEE), new Pair(RIGHT_KNEE, RIGHT_ANKLE));
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ addCameraFragment();
+ }
+
+ private void addCameraFragment() {
+ posenet = new Posenet(this);
+
+ poseNetFragment = PoseNetFragment.newInstance();
+ poseNetFragment.setCameraDataDealListener(this);
+ // poseNetFragment.setFacingCamera(lensFacing);
+ getSupportFragmentManager().popBackStack();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.container, poseNetFragment)
+ .commitAllowingStateLoss();
+ }
+
+ @Override
+ public void dataDeal(Image image, SurfaceView surfaceView) {
+ if (image == null || image.getPlanes() == null) {
+ return;
+ }
+ this.surfaceView = surfaceView;
+ fillBytes(image.getPlanes(), yuvBytes);
+ ImageUtils.convertYUV420ToARGB8888(yuvBytes[0], yuvBytes[1], yuvBytes[2],
+ PREVIEW_WIDTH, PREVIEW_HEIGHT,
+ image.getPlanes()[0].getRowStride(),
+ image.getPlanes()[1].getRowStride(),
+ image.getPlanes()[1].getPixelStride(),
+ rgbBytes);
+
+ Bitmap imageBitmap = Bitmap.createBitmap(
+ rgbBytes, PREVIEW_WIDTH, PREVIEW_HEIGHT,
+ Bitmap.Config.ARGB_8888);
+ Matrix rotateMatrix = new Matrix();
+ rotateMatrix.postRotate(90.0f);
+
+ Bitmap rotatedBitmap = Bitmap.createBitmap(
+ imageBitmap, 0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT,
+ rotateMatrix, true
+ );
+ image.close();
+ processImage(rotatedBitmap);
+ }
+
+
+ /**
+ * Fill the yuvBytes with data from image planes.
+ */
+ private void fillBytes(Image.Plane[] planes, byte[][] yuvBytes) {
+ // Row stride is the total number of bytes occupied in memory by a row of an image.
+ // Because of the variable row stride it's not possible to know in
+ // advance the actual necessary dimensions of the yuv planes
+ for (int i = 0; i < planes.length; ++i) {
+ ByteBuffer buffer = planes[i].getBuffer();
+ if (yuvBytes[i] == null) {
+ yuvBytes[i] = new byte[buffer.capacity()];
+ }
+ buffer.get(yuvBytes[i]);
+ }
+ }
+
+ /**
+ * Crop Bitmap to maintain aspect ratio of model input.
+ */
+ private Bitmap cropBitmap(Bitmap bitmap) {
+ float bitmapRatio = bitmap.getHeight() / bitmap.getWidth();
+ float modelInputRatio = MODEL_HEIGHT / MODEL_WIDTH;
+ double maxDifference = 1.0E-5D;
+ float cropHeight = modelInputRatio - bitmapRatio;
+
+ if (Math.abs(cropHeight) < maxDifference) {
+ return bitmap;
+ } else {
+ Bitmap croppedBitmap;
+ if (modelInputRatio < bitmapRatio) {
+ cropHeight = (float) bitmap.getHeight() - (float) bitmap.getWidth() / modelInputRatio;
+ croppedBitmap = Bitmap.createBitmap(bitmap,
+ 0, (int) (cropHeight / 2), bitmap.getWidth(), (int) (bitmap.getHeight() - cropHeight));
+ } else {
+ cropHeight = (float) bitmap.getWidth() - (float) bitmap.getHeight() * modelInputRatio;
+ croppedBitmap = Bitmap.createBitmap(bitmap,
+ (int) (cropHeight / 2), 0, (int) (bitmap.getWidth() - cropHeight), bitmap.getHeight());
+ }
+ return croppedBitmap;
+ }
+ }
+
+ /**
+ * Set the paint color and size.
+ */
+ private void setPaint() {
+ paint.setColor(getResources().getColor(R.color.text_blue));
+ paint.setTextSize(80.0f);
+ paint.setStrokeWidth(8.0f);
+ }
+
+ /**
+ * Draw bitmap on Canvas.
+ */
+ private void draw(Canvas canvas, Posenet.Person person, Bitmap bitmap) {
+ canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
+ // Draw `bitmap` and `person` in square canvas.
+ int screenWidth, screenHeight;
+ int left, right, top, bottom;
+ if (canvas.getHeight() > canvas.getWidth()) {
+ screenWidth = canvas.getWidth();
+ screenHeight = canvas.getWidth();
+ left = 0;
+ top = (canvas.getHeight() - canvas.getWidth()) / 2;
+ } else {
+ screenWidth = canvas.getHeight();
+ screenHeight = canvas.getHeight();
+ left = (canvas.getWidth() - canvas.getHeight()) / 2;
+ top = 0;
+ }
+ right = left + screenWidth;
+ bottom = top + screenHeight;
+
+ setPaint();
+ canvas.drawBitmap(
+ bitmap,
+ new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
+ new Rect(left, top, right, bottom), paint);
+
+ float widthRatio = screenWidth / MODEL_WIDTH;
+ float heightRatio = screenHeight / MODEL_HEIGHT;
+
+ for (Posenet.KeyPoint keyPoint : person.keyPoints) {
+ if (keyPoint.score > minConfidence) {
+ Posenet.Position position = keyPoint.position;
+ float adjustedX = position.x * widthRatio + left;
+ float adjustedY = position.y * heightRatio + top;
+ canvas.drawCircle(adjustedX, adjustedY, circleRadius, paint);
+ }
+ }
+
+ for (int i = 0; i < bodyJoints.size(); i++) {
+ Pair line = (Pair) bodyJoints.get(i);
+ Posenet.BodyPart first = (Posenet.BodyPart) line.first;
+ Posenet.BodyPart second = (Posenet.BodyPart) line.second;
+
+ if (person.keyPoints.get(first.ordinal()).score > minConfidence &
+ person.keyPoints.get(second.ordinal()).score > minConfidence) {
+ canvas.drawLine(
+ person.keyPoints.get(first.ordinal()).position.x * widthRatio + left,
+ person.keyPoints.get(first.ordinal()).position.y * heightRatio + top,
+ person.keyPoints.get(second.ordinal()).position.x * widthRatio + left,
+ person.keyPoints.get(second.ordinal()).position.y * heightRatio + top, paint);
+ }
+ }
+
+ canvas.drawText(String.format("Score: %.2f", person.score),
+ (15.0f * widthRatio), (30.0f * heightRatio + bottom), paint);
+ canvas.drawText(String.format("Time: %.2f ms", posenet.lastInferenceTimeNanos * 1.0f / 1_000_000),
+ (15.0f * widthRatio), (50.0f * heightRatio + bottom), paint
+ );
+
+ // Draw!
+ surfaceView.getHolder().unlockCanvasAndPost(canvas);
+ }
+
+ /**
+ * Process image using Posenet library.
+ */
+ private void processImage(Bitmap bitmap) {
+ // Crop bitmap.
+ Bitmap croppedBitmap = cropBitmap(bitmap);
+ // Created scaled version of bitmap for model input.
+ Bitmap scaledBitmap = Bitmap.createScaledBitmap(croppedBitmap, MODEL_WIDTH, MODEL_HEIGHT, true);
+ // Perform inference.
+ Posenet.Person person = posenet.estimateSinglePose(scaledBitmap);
+ Canvas canvas = surfaceView.getHolder().lockCanvas();
+ draw(canvas, person, scaledBitmap);
+ }
+
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable-v24/ic_launcher_foreground.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 00000000000..2b068d11462
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable-v24/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/circle_bg.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/circle_bg.xml
new file mode 100644
index 00000000000..9c02d1e0596
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/circle_bg.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/ic_launcher_background.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 00000000000..07d5da9cbf1
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/image.jpg b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/image.jpg
new file mode 100644
index 00000000000..9615b7cc73c
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/image.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/logo2.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/logo2.png
new file mode 100644
index 00000000000..c90f1dda439
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/logo2.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/activity_main.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/activity_main.xml
new file mode 100644
index 00000000000..c91bccecd67
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/activity_main.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/fragment_pose_net.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/fragment_pose_net.xml
new file mode 100644
index 00000000000..2d0d8f8e584
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/fragment_pose_net.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 00000000000..a571e60098c
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..61da551c559
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 00000000000..c41dd285319
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..db5080a7527
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 00000000000..6dba46dab19
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..da31a871c8d
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 00000000000..15ac681720f
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..b216f2d313c
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 00000000000..f25a4197447
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 00000000000..e96783ccce8
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/colors.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/colors.xml
new file mode 100644
index 00000000000..539651e1d44
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/colors.xml
@@ -0,0 +1,19 @@
+
+
+ #6200EE
+ #3700B3
+ #03DAC5
+
+ #66000000
+
+ #ffffff
+ #000000
+ #A69D9D
+ #424242
+
+ #6DA7FF
+ #F8E71C
+ #FF844D
+ #66B50A
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/strings.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/strings.xml
new file mode 100644
index 00000000000..30d982a08b1
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+ PoseNetDemo
+
+ Hello blank fragment
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/styles.xml b/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/styles.xml
new file mode 100644
index 00000000000..13f74a4612a
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/res/values/styles.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/test/java/com/mindspore/posenet/ExampleUnitTest.java b/model_zoo/official/lite/Himindspore/posenet/src/test/java/com/mindspore/posenet/ExampleUnitTest.java
new file mode 100644
index 00000000000..b07f7c75c40
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/posenet/src/test/java/com/mindspore/posenet/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.mindspore.posenet;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/settings.gradle b/model_zoo/official/lite/Himindspore/settings.gradle
index aa8bc5841bf..71505fc553d 100644
--- a/model_zoo/official/lite/Himindspore/settings.gradle
+++ b/model_zoo/official/lite/Himindspore/settings.gradle
@@ -1,2 +1,5 @@
+include ':imageObject'
+include ':styletransfer'
+include ':posenet'
include ':app'
rootProject.name = "HiMindSpore"
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/.gitignore b/model_zoo/official/lite/Himindspore/styletransfer/.gitignore
new file mode 100644
index 00000000000..42afabfd2ab
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/build.gradle b/model_zoo/official/lite/Himindspore/styletransfer/build.gradle
new file mode 100644
index 00000000000..eb480f75566
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/build.gradle
@@ -0,0 +1,79 @@
+plugins {
+ id 'com.android.library'
+}
+
+android {
+ compileSdkVersion 30
+ buildToolsVersion "30.0.1"
+
+ defaultConfig {
+ minSdkVersion 21
+ targetSdkVersion 30
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ javaCompileOptions {
+ annotationProcessorOptions {
+ arguments = [moduleName: project.getName()]
+ }
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+
+ aaptOptions {
+ noCompress "ms"
+ }
+
+ lintOptions {
+ checkReleaseBuilds false
+ // Or, if you prefer, you can continue to check for errors in release builds,
+ // but continue the build even when errors are found:
+ abortOnError false
+ }
+
+ repositories {
+ google()
+ jcenter()
+ flatDir {
+ dirs 'libs'
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+}
+
+// Download default models; if you wish to use your own models then
+// place them in the "assets" directory and comment out this line.
+apply from: 'download.gradle'
+
+dependencies {
+ implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+ implementation 'androidx.recyclerview:recyclerview:1.1.0'
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
+ implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.2'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
+
+ implementation 'com.github.bumptech.glide:glide:4.11.0'
+ annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
+
+ implementation 'com.alibaba:arouter-api:1.2.1'
+ annotationProcessor 'com.alibaba:arouter-compiler:1.1.2'
+
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/download.gradle b/model_zoo/official/lite/Himindspore/styletransfer/download.gradle
new file mode 100644
index 00000000000..5a5e4fe2cd6
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/download.gradle
@@ -0,0 +1,88 @@
+/**
+ * To download necessary library from HuaWei server.
+ * Including mindspore-lite .so file, minddata-lite .so file and model file.
+ * The libraries can be downloaded manually.
+ */
+def mindsporeLite_Version = "mindspore-lite-maven-1.0.1"
+def targetPredictModelFile = "src/main/assets/style_predict_quant.ms"
+def targetTransferModelFile = "src/main/assets/style_transfer_quant.ms"
+def modelPredictDownloadUrl = "https://download.mindspore.cn/model_zoo/official/lite/style_lite/style_predict_quant.ms"
+def modelTransferDownloadUrl = "https://download.mindspore.cn/model_zoo/official/lite/style_lite/style_transfer_quant.ms"
+def mindsporeLiteDownloadUrl = "https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.0.1/lite/java/${mindsporeLite_Version}.zip"
+def mindSporeLibrary = "libs/${mindsporeLite_Version}.zip"
+def cleantargetMindSporeInclude = "libs"
+def targetMindSporeInclude = "libs/"
+
+
+task downloadPredictModelFile(type: DownloadUrlTask) {
+ doFirst {
+ println "Downloading ${modelPredictDownloadUrl}"
+ }
+ sourceUrl = "${modelPredictDownloadUrl}"
+ target = file("${targetPredictModelFile}")
+}
+
+task downloadTransferModelFile(type: DownloadUrlTask) {
+ doFirst {
+ println "Downloading ${modelTransferDownloadUrl}"
+ }
+ sourceUrl = "${modelTransferDownloadUrl}"
+ target = file("${targetTransferModelFile}")
+}
+
+
+task downloadMindSporeLibrary(type: DownloadUrlTask) {
+ doFirst {
+ println "Downloading ${mindsporeLiteDownloadUrl}"
+ }
+ sourceUrl = "${mindsporeLiteDownloadUrl}"
+ target = file("${mindSporeLibrary}")
+}
+
+task unzipMindSporeInclude(type: Copy, dependsOn: ['downloadMindSporeLibrary']) {
+ doFirst {
+ println "Unzipping ${mindSporeLibrary}"
+ }
+ from zipTree("${mindSporeLibrary}")
+ into "${targetMindSporeInclude}"
+}
+
+task cleanUnusedmindsporeFiles(type: Delete, dependsOn: ['unzipMindSporeInclude']) {
+ delete fileTree("${cleantargetMindSporeInclude}").matching {
+ include "*.zip"
+ }
+}
+
+if (file("libs/mindspore-lite-1.0.1.aar").exists()) {
+ downloadMindSporeLibrary.enabled = false
+ unzipMindSporeInclude.enabled = false
+ cleanUnusedmindsporeFiles.enabled = false
+}
+
+
+if (file("src/main/assets/style_transfer_quant.ms").exists()) {
+ downloadTransferModelFile.enabled = false
+}
+
+if (file("src/main/assets/style_predict_quant.ms").exists()) {
+ downloadPredictModelFile.enabled = false
+}
+
+preBuild.dependsOn downloadPredictModelFile
+preBuild.dependsOn downloadTransferModelFile
+preBuild.dependsOn downloadMindSporeLibrary
+preBuild.dependsOn unzipMindSporeInclude
+preBuild.dependsOn cleanUnusedmindsporeFiles
+
+class DownloadUrlTask extends DefaultTask {
+ @Input
+ String sourceUrl
+
+ @OutputFile
+ File target
+
+ @TaskAction
+ void download() {
+ ant.get(src: sourceUrl, dest: target)
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/proguard-rules.pro b/model_zoo/official/lite/Himindspore/styletransfer/proguard-rules.pro
new file mode 100644
index 00000000000..481bb434814
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/androidTest/java/com/mindspore/styletransfer/ExampleInstrumentedTest.java b/model_zoo/official/lite/Himindspore/styletransfer/src/androidTest/java/com/mindspore/styletransfer/ExampleInstrumentedTest.java
new file mode 100644
index 00000000000..72bee19eeb5
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/androidTest/java/com/mindspore/styletransfer/ExampleInstrumentedTest.java
@@ -0,0 +1,26 @@
+package com.mindspore.styletransfer;
+
+import android.content.Context;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ assertEquals("com.mindspore.styletransfer", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/AndroidManifest.xml b/model_zoo/official/lite/Himindspore/styletransfer/src/main/AndroidManifest.xml
new file mode 100644
index 00000000000..6dc2abdcd25
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/main/AndroidManifest.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style0.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style0.jpg
new file mode 100644
index 00000000000..8d0cab6a99d
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style0.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style1.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style1.jpg
new file mode 100644
index 00000000000..5337b50dad1
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style1.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style10.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style10.jpg
new file mode 100644
index 00000000000..d84b9fe27a7
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style10.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style11.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style11.jpg
new file mode 100644
index 00000000000..017dfe27b5d
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style11.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style12.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style12.jpg
new file mode 100644
index 00000000000..4f5b90cea7b
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style12.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style13.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style13.jpg
new file mode 100644
index 00000000000..2411f78fd93
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style13.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style14.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style14.jpg
new file mode 100644
index 00000000000..26659430197
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style14.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style15.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style15.jpg
new file mode 100644
index 00000000000..6256956784e
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style15.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style16.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style16.jpg
new file mode 100644
index 00000000000..7356c927c4b
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style16.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style17.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style17.jpg
new file mode 100644
index 00000000000..f1194aa62ff
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style17.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style18.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style18.jpg
new file mode 100644
index 00000000000..519b9e7fbed
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style18.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style19.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style19.jpg
new file mode 100644
index 00000000000..23849a8b65b
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style19.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style2.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style2.jpg
new file mode 100644
index 00000000000..e28061a2ba1
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style2.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style20.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style20.jpg
new file mode 100644
index 00000000000..38dc18b0eea
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style20.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style3.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style3.jpg
new file mode 100644
index 00000000000..d4279dc7d06
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style3.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style4.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style4.jpg
new file mode 100644
index 00000000000..3a1ef037476
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style4.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style5.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style5.jpg
new file mode 100644
index 00000000000..a9d10519445
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style5.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style6.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style6.jpg
new file mode 100644
index 00000000000..fc02154c1c8
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style6.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style7.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style7.jpg
new file mode 100644
index 00000000000..74b046d50b4
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style7.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style8.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style8.jpg
new file mode 100644
index 00000000000..3a5c7fdcc8e
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style8.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style9.jpg b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style9.jpg
new file mode 100644
index 00000000000..2c3ae1708b1
Binary files /dev/null and b/model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style9.jpg differ
diff --git a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/help/BitmapUtils.java b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/BitmapUtils.java
similarity index 88%
rename from model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/help/BitmapUtils.java
rename to model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/BitmapUtils.java
index 1bacc13dc35..b3820550d23 100644
--- a/model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/objectdetection/help/BitmapUtils.java
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/BitmapUtils.java
@@ -1,4 +1,19 @@
-package com.mindspore.himindspore.objectdetection.help;
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.styletransfer;
import android.app.Activity;
import android.database.Cursor;
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ImageUtils.java b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ImageUtils.java
new file mode 100644
index 00000000000..53382b6869f
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ImageUtils.java
@@ -0,0 +1,201 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.styletransfer;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.Matrix;
+import android.graphics.RectF;
+
+import androidx.annotation.NonNull;
+import androidx.exifinterface.media.ExifInterface;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class ImageUtils {
+
+ private static Matrix decodeExifOrientation(int orientation) {
+ Matrix matrix = new Matrix();
+
+ switch (orientation) {
+ case ExifInterface.ORIENTATION_NORMAL:
+ case ExifInterface.ORIENTATION_UNDEFINED:
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_90:
+ matrix.postRotate(90F);
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_180:
+ matrix.postRotate(180F);
+ break;
+ case ExifInterface.ORIENTATION_ROTATE_270:
+ matrix.postRotate(270F);
+ break;
+ case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
+ matrix.postScale(-1F, 1F);
+ break;
+ case ExifInterface.ORIENTATION_FLIP_VERTICAL:
+ matrix.postScale(1F, -1F);
+ break;
+ case ExifInterface.ORIENTATION_TRANSPOSE:
+ matrix.postScale(-1F, 1F);
+ matrix.postRotate(270F);
+ break;
+ case ExifInterface.ORIENTATION_TRANSVERSE:
+ matrix.postScale(-1F, 1F);
+ matrix.postRotate(90F);
+ break;
+
+ default:
+ try {
+ new IllegalArgumentException("Invalid orientation: " + orientation);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ }
+ return matrix;
+ }
+
+ public void setExifOrientation(@NonNull String filePath, @NonNull String value) {
+ try {
+ ExifInterface exif = new ExifInterface(filePath);
+ exif.setAttribute(ExifInterface.TAG_ORIENTATION, value);
+ exif.saveAttributes();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public int computeExifOrientation(int rotationDegrees, boolean mirrored) {
+ if (rotationDegrees == 0 && !mirrored) {
+ return ExifInterface.ORIENTATION_NORMAL;
+ } else if (rotationDegrees == 0 && mirrored) {
+ return ExifInterface.ORIENTATION_FLIP_HORIZONTAL;
+ } else if (rotationDegrees == 180 && !mirrored) {
+ return ExifInterface.ORIENTATION_ROTATE_180;
+ } else if (rotationDegrees == 180 && mirrored) {
+ return ExifInterface.ORIENTATION_FLIP_VERTICAL;
+ } else if (rotationDegrees == 90 && !mirrored) {
+ return ExifInterface.ORIENTATION_ROTATE_90;
+ } else if (rotationDegrees == 90 && mirrored) {
+ return ExifInterface.ORIENTATION_TRANSPOSE;
+ } else if (rotationDegrees == 270 && !mirrored) {
+ return ExifInterface.ORIENTATION_ROTATE_270;
+ } else if (rotationDegrees == 270 && mirrored) {
+ return ExifInterface.ORIENTATION_TRANSVERSE;
+ } else {
+ return ExifInterface.ORIENTATION_UNDEFINED;
+ }
+ }
+
+ public static Bitmap decodeBitmap(@NonNull File file) {
+ Bitmap finalBitmap = null;
+ try {
+ ExifInterface exif = new ExifInterface(file.getAbsolutePath());
+
+ Matrix transformation = decodeExifOrientation(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_ROTATE_90));
+
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
+ finalBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), transformation, true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return finalBitmap;
+ }
+
+
+ public static Bitmap scaleBitmapAndKeepRatio(Bitmap targetBmp, int reqHeightInPixels, int reqWidthInPixels) {
+ if (targetBmp.getHeight() == reqHeightInPixels && targetBmp.getWidth() == reqWidthInPixels) {
+ return targetBmp;
+ }
+
+ Matrix matrix = new Matrix();
+ matrix.setRectToRect(new RectF(0f, 0f,
+ targetBmp.getWidth(),
+ targetBmp.getHeight()
+ ), new RectF(0f, 0f,
+ reqWidthInPixels,
+ reqHeightInPixels
+ ), Matrix.ScaleToFit.FILL);
+
+ return Bitmap.createBitmap(
+ targetBmp, 0, 0,
+ targetBmp.getWidth(),
+ targetBmp.getHeight(), matrix, true
+ );
+ }
+
+ public static Bitmap loadBitmapFromResources(Context context, String path) {
+ try {
+ InputStream inputStream = context.getAssets().open(path);
+ return BitmapFactory.decodeStream(inputStream);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static ByteBuffer bitmapToByteBuffer(Bitmap bitmapIn, int width, int height, float mean, float std) {
+ Bitmap bitmap = scaleBitmapAndKeepRatio(bitmapIn, width, height);
+ ByteBuffer inputImage = ByteBuffer.allocateDirect(1 * width * height * 3 * 4);
+ inputImage.order(ByteOrder.nativeOrder());
+ inputImage.rewind();
+ int[] intValues = new int[width * height];
+ bitmap.getPixels(intValues, 0, width, 0, 0, width, height);
+ int pixel = 0;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int value = intValues[pixel++];
+ inputImage.putFloat(((float) (value >> 16 & 255) - mean) / std);
+ inputImage.putFloat(((float) (value >> 8 & 255) - mean) / std);
+ inputImage.putFloat(((float) (value & 255) - mean) / std);
+ }
+ }
+ inputImage.rewind();
+ return inputImage;
+ }
+
+
+ public static Bitmap convertArrayToBitmap(float[][][][] imageArray, int imageWidth, int imageHeight) {
+ Bitmap styledImage = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
+
+ for (int x = 0; x < imageArray[0].length; x++) {
+ for (int y = 0; y < imageArray[0][0].length; y++) {
+
+ int color = Color.rgb((int) (imageArray[0][x][y][0] * (float) 255),
+ (int) (imageArray[0][x][y][1] * (float) 255),
+ (int) (imageArray[0][x][y][2] * (float) 255));
+ // this y, x is in the correct order!!!
+ styledImage.setPixel(y, x, color);
+ }
+ }
+ return styledImage;
+ }
+
+ public Bitmap createEmptyBitmap(int imageWidth, int imageHeigth, int color) {
+ Bitmap ret = Bitmap.createBitmap(imageWidth, imageHeigth, Bitmap.Config.RGB_565);
+ if (color != 0) {
+ ret.eraseColor(color);
+ }
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ModelExecutionResult.java b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ModelExecutionResult.java
new file mode 100644
index 00000000000..7ec7c12f5a1
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ModelExecutionResult.java
@@ -0,0 +1,112 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.styletransfer;
+
+import android.graphics.Bitmap;
+
+public class ModelExecutionResult {
+ private Bitmap styledImage;
+ private long preProcessTime;
+ private long stylePredictTime;
+ private long styleTransferTime;
+ private long postProcessTime;
+ private long totalExecutionTime;
+ private String executionLog;
+ private String errorMessage;
+
+
+ public ModelExecutionResult(Bitmap styledImage, long preProcessTime, long stylePredictTime, long styleTransferTime, long postProcessTime, long totalExecutionTime, String executionLog) {
+ this.styledImage = styledImage;
+ this.preProcessTime = preProcessTime;
+ this.stylePredictTime = stylePredictTime;
+ this.styleTransferTime = styleTransferTime;
+ this.postProcessTime = postProcessTime;
+ this.totalExecutionTime = totalExecutionTime;
+ this.executionLog = executionLog;
+ }
+
+ public Bitmap getStyledImage() {
+ return styledImage;
+ }
+
+ public ModelExecutionResult setStyledImage(Bitmap styledImage) {
+ this.styledImage = styledImage;
+ return this;
+ }
+
+ public long getPreProcessTime() {
+ return preProcessTime;
+ }
+
+ public ModelExecutionResult setPreProcessTime(long preProcessTime) {
+ this.preProcessTime = preProcessTime;
+ return this;
+ }
+
+ public long getStylePredictTime() {
+ return stylePredictTime;
+ }
+
+ public ModelExecutionResult setStylePredictTime(long stylePredictTime) {
+ this.stylePredictTime = stylePredictTime;
+ return this;
+ }
+
+ public long getStyleTransferTime() {
+ return styleTransferTime;
+ }
+
+ public ModelExecutionResult setStyleTransferTime(long styleTransferTime) {
+ this.styleTransferTime = styleTransferTime;
+ return this;
+ }
+
+ public long getPostProcessTime() {
+ return postProcessTime;
+ }
+
+ public ModelExecutionResult setPostProcessTime(long postProcessTime) {
+ this.postProcessTime = postProcessTime;
+ return this;
+ }
+
+ public long getTotalExecutionTime() {
+ return totalExecutionTime;
+ }
+
+ public ModelExecutionResult setTotalExecutionTime(long totalExecutionTime) {
+ this.totalExecutionTime = totalExecutionTime;
+ return this;
+ }
+
+ public String getExecutionLog() {
+ return executionLog;
+ }
+
+ public ModelExecutionResult setExecutionLog(String executionLog) {
+ this.executionLog = executionLog;
+ return this;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public ModelExecutionResult setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ return this;
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/OnListFragmentInteractionListener.java b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/OnListFragmentInteractionListener.java
new file mode 100644
index 00000000000..9ba62bd62f2
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/OnListFragmentInteractionListener.java
@@ -0,0 +1,5 @@
+package com.mindspore.styletransfer;
+
+public interface OnListFragmentInteractionListener {
+ void onListFragmentInteraction(String item);
+}
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleMainActivity.java b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleMainActivity.java
new file mode 100644
index 00000000000..f1d731eeef3
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleMainActivity.java
@@ -0,0 +1,202 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mindspore.styletransfer;
+
+import android.content.Context;
+import android.net.Uri;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+
+import java.util.List;
+
+public class StyleRecyclerViewAdapter extends RecyclerView.Adapter {
+
+ private View.OnClickListener mOnClickListener;
+ private List stylesList;
+ private Context context;
+ private OnListFragmentInteractionListener mListener;
+
+ public StyleRecyclerViewAdapter(Context context, List stylesList, OnListFragmentInteractionListener mListener) {
+ this.stylesList = stylesList;
+ this.context = context;
+ this.mListener = mListener;
+
+ this.mOnClickListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+
+ }
+ };
+
+ this.mOnClickListener = (View.OnClickListener) (new View.OnClickListener() {
+ public final void onClick(View v) {
+
+ if (v.getTag() != null && v.getTag() instanceof String) {
+ mListener.onListFragmentInteraction(String.valueOf(v.getTag()));
+ }
+ }
+ });
+ }
+
+ @NonNull
+ @Override
+ public StyleItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ View view = LayoutInflater.from(context)
+ .inflate(R.layout.image_item, parent, false);
+ return new StyleItemViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull StyleItemViewHolder holder, int position) {
+ String imagePath = stylesList.get(position);
+ Glide.with(context).
+ load(Uri.parse("file:///android_asset/thumbnails/" + imagePath)).
+ centerInside().
+ into(holder.getImageView());
+
+ View view = holder.getMView();
+ view.setTag(imagePath);
+ view.setOnClickListener(this.mOnClickListener);
+ }
+
+
+ @Override
+ public int getItemCount() {
+ return stylesList == null ? 0 : stylesList.size();
+ }
+
+
+ public class StyleItemViewHolder extends RecyclerView.ViewHolder {
+ private ImageView imageView;
+ private final View mView;
+
+ public final ImageView getImageView() {
+ return this.imageView;
+ }
+
+ public final void setImageView(ImageView imageView) {
+ this.imageView = imageView;
+ }
+
+ public final View getMView() {
+ return this.mView;
+ }
+
+ public StyleItemViewHolder(View mView) {
+ super(mView);
+ this.mView = mView;
+ this.imageView = mView.findViewById(R.id.image_view);
+ }
+ }
+}
diff --git a/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleTransferModelExecutor.java b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleTransferModelExecutor.java
new file mode 100644
index 00000000000..4d58a2f5658
--- /dev/null
+++ b/model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleTransferModelExecutor.java
@@ -0,0 +1,264 @@
+/**
+ * Copyright 2020 Huawei Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *