Browse Source

fix style transfer demos

format aar

format all codes
tags/v1.1.0
hukang hwx963878 5 years ago
parent
commit
f303e42129
81 changed files with 692 additions and 307 deletions
  1. +13
    -4
      model_zoo/official/lite/Himindspore/app/build.gradle
  2. +6
    -2
      model_zoo/official/lite/Himindspore/app/src/main/AndroidManifest.xml
  3. +61
    -13
      model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/SplashActivity.java
  4. +1
    -1
      model_zoo/official/lite/Himindspore/app/src/main/res/values/styles.xml
  5. +4
    -0
      model_zoo/official/lite/Himindspore/build.gradle
  6. +0
    -1
      model_zoo/official/lite/Himindspore/imageObject/build.gradle
  7. +1
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/.gitignore
  8. +66
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/build.gradle
  9. +0
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/consumer-rules.pro
  10. +57
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/download.gradle
  11. +21
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/proguard-rules.pro
  12. +26
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/src/androidTest/java/com/mindspore/mindsporelibrary/ExampleInstrumentedTest.java
  13. +4
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/src/main/AndroidManifest.xml
  14. +17
    -0
      model_zoo/official/lite/Himindspore/mindsporelibrary/src/test/java/com/mindspore/mindsporelibrary/ExampleUnitTest.java
  15. +5
    -5
      model_zoo/official/lite/Himindspore/posenet/build.gradle
  16. +0
    -39
      model_zoo/official/lite/Himindspore/posenet/download.gradle
  17. +4
    -4
      model_zoo/official/lite/Himindspore/posenet/src/main/AndroidManifest.xml
  18. +1
    -1
      model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PoseNetFragment.java
  19. +2
    -2
      model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java
  20. +0
    -30
      model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable-v24/ic_launcher_foreground.xml
  21. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable-xxhdpi/logo2.png
  22. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_circle_bg.xml
  23. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_ic_launcher_background.xml
  24. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_image.jpg
  25. BIN
      model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_logo.png
  26. +1
    -1
      model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/posenet_activity_main.xml
  27. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/posenet_fragment_pose_net.xml
  28. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/posenet_ic_launcher.png
  29. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/posenet_ic_launcher_round.png
  30. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/posenet_ic_launcher.png
  31. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/posenet_ic_launcher_round.png
  32. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/posenet_ic_launcher.png
  33. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/posenet_ic_launcher_round.png
  34. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/posenet_ic_launcher.png
  35. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/posenet_ic_launcher_round.png
  36. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/posenet_ic_launcher.png
  37. +0
    -0
      model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/posenet_ic_launcher_round.png
  38. +12
    -12
      model_zoo/official/lite/Himindspore/posenet/src/main/res/values/colors.xml
  39. +2
    -2
      model_zoo/official/lite/Himindspore/posenet/src/main/res/values/strings.xml
  40. +4
    -4
      model_zoo/official/lite/Himindspore/posenet/src/main/res/values/styles.xml
  41. +1
    -0
      model_zoo/official/lite/Himindspore/settings.gradle
  42. +3
    -2
      model_zoo/official/lite/Himindspore/styletransfer/build.gradle
  43. +0
    -39
      model_zoo/official/lite/Himindspore/styletransfer/download.gradle
  44. +13
    -1
      model_zoo/official/lite/Himindspore/styletransfer/src/main/AndroidManifest.xml
  45. +21
    -1
      model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/BitmapUtils.java
  46. +65
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ImageUtils.java
  47. +9
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/OnBackgroundImageListener.java
  48. +0
    -5
      model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/OnListFragmentInteractionListener.java
  49. +129
    -62
      model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleMainActivity.java
  50. +17
    -31
      model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleRecyclerViewAdapter.java
  51. +0
    -15
      model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleTransferModelExecutor.java
  52. BIN
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/add.jpg
  53. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style0.jpg
  54. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style1.jpg
  55. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style10.jpg
  56. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style11.jpg
  57. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style12.jpg
  58. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style13.jpg
  59. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style14.jpg
  60. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style15.jpg
  61. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style16.jpg
  62. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style17.jpg
  63. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style18.jpg
  64. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style19.jpg
  65. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style2.jpg
  66. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style20.jpg
  67. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style3.jpg
  68. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style4.jpg
  69. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style5.jpg
  70. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style6.jpg
  71. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style7.jpg
  72. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style8.jpg
  73. +0
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style9.jpg
  74. BIN
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style_chose.png
  75. +20
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable/progressbar.xml
  76. +86
    -10
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/layout/activity_main_style.xml
  77. +6
    -13
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/layout/image_item.xml
  78. +2
    -1
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/values/strings.xml
  79. +6
    -0
      model_zoo/official/lite/Himindspore/styletransfer/src/main/res/xml/style_file_paths.xml
  80. +5
    -5
      model_zoo/official/lite/posenet/app/src/main/AndroidManifest.xml
  81. +1
    -1
      model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java

+ 13
- 4
model_zoo/official/lite/Himindspore/app/build.gradle View File

@@ -8,8 +8,8 @@ android {
applicationId "com.mindspore.himindspore"
minSdkVersion 21
targetSdkVersion 30
versionCode 2
versionName "1.1.0"
versionCode 3
versionName "1.1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
@@ -25,13 +25,23 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}

}

aaptOptions {
noCompress "ms"
}

repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }

flatDir {
dirs 'libs', '../mindsporelibrary/libs'
}
}


compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@@ -45,7 +55,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'



+ 6
- 2
model_zoo/official/lite/Himindspore/app/src/main/AndroidManifest.xml View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mindspore.himindspore">

<uses-permission android:name="android.permission.CAMERA" />
@@ -21,10 +22,11 @@
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:replace="android:label"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.actions"
android:resource="@xml/file_paths" />
android:resource="@xml/style_file_paths" />

<activity
android:name=".SplashActivity"
@@ -41,10 +43,12 @@
android:name="androidx.core.content.FileProvider"
android:authorities="com.mindspore.himindspore.fileprovider"
android:exported="false"
tools:replace="android:authorities"
android:grantUriPermissions="true">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
android:resource="@xml/style_file_paths" />
</provider>
</application>


+ 61
- 13
model_zoo/official/lite/Himindspore/app/src/main/java/com/mindspore/himindspore/SplashActivity.java View File

@@ -24,6 +24,7 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
@@ -32,6 +33,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;

import com.alibaba.android.arouter.facade.annotation.Route;
@@ -48,9 +50,12 @@ import java.io.File;
public class SplashActivity extends BaseActivity<MainPresenter> implements MainContract.View {

private static final String TAG = "SplashActivity";

private static final String[] PERMISSIONS = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
private static final int REQUEST_PERMISSION = 1;

private boolean isHasPermssion;
private boolean isAllGranted;
private int now_version;

private ProgressDialog progressDialog;
@@ -83,13 +88,27 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

}

private void requestPermissions() {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}, REQUEST_PERMISSION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
isAllGranted = checkPermissionAllGranted(PERMISSIONS);
if (!isAllGranted) {
ActivityCompat.requestPermissions(this, PERMISSIONS, REQUEST_PERMISSION);
}
} else {
isAllGranted = true;
}
}


private boolean checkPermissionAllGranted(String[] permissions) {
for (String permission : permissions) {
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}

/**
@@ -98,17 +117,47 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (REQUEST_PERMISSION == requestCode) {
isHasPermssion = true;
isAllGranted = true;

for (int grant : grantResults) {
if (grant != PackageManager.PERMISSION_GRANTED) {
isAllGranted = false;
break;
}
}
if (!isAllGranted) {
openAppDetails();
}
}
}

private void openAppDetails() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("HiMindSpore需要访问 “相机” 和 “外部存储器”,请到 “应用信息 -> 权限” 中授予!");
builder.setPositiveButton("去手动授权", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(intent);
}
});
builder.setNegativeButton("取消", null);
builder.show();
}

private void getUpdateInfo() {
presenter.getUpdateInfo();
}


public void onClickImage(View view) {
if (isHasPermssion) {
if (isAllGranted) {
ARouter.getInstance().build("/imageobject/ImageCameraActivity")
.withInt("OPEN_TYPE", 1).navigation();
} else {
@@ -117,7 +166,7 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
}

public void onClickGarbage(View view) {
if (isHasPermssion) {
if (isAllGranted) {
ARouter.getInstance().build("/imageobject/ImageCameraActivity")
.withInt("OPEN_TYPE", 2).navigation();
} else {
@@ -126,7 +175,7 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
}

public void onClickPhotoDetection(View view) {
if (isHasPermssion) {
if (isAllGranted) {
ARouter.getInstance().build("/imageobject/ObjectPhotoActivity").navigation();
} else {
requestPermissions();
@@ -134,7 +183,7 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
}

public void onClickCameraDetection(View view) {
if (isHasPermssion) {
if (isAllGranted) {
ARouter.getInstance().build("/imageobject/ObjectCameraActivity").navigation();
} else {
requestPermissions();
@@ -142,7 +191,7 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
}

public void onClickPoseNet(View view) {
if (isHasPermssion) {
if (isAllGranted) {
ARouter.getInstance().build("/posenet/PosenetMainActivity").navigation(this);
} else {
requestPermissions();
@@ -150,7 +199,7 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
}

public void onClickStyleTransfer(View view) {
if (isHasPermssion) {
if (isAllGranted) {
ARouter.getInstance().build("/styletransfer/StyleMainActivity").navigation(this);
} else {
requestPermissions();
@@ -219,7 +268,6 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC


public void showUpdate(final UpdateInfoBean updateInfo) {

if (now_version == updateInfo.getVersionCode()) {
Toast.makeText(this, "已经是最新版本", Toast.LENGTH_SHORT).show();
Log.d(TAG + "版本号是", "onResponse: " + now_version);


+ 1
- 1
model_zoo/official/lite/Himindspore/app/src/main/res/values/styles.xml View File

@@ -1,6 +1,6 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>


+ 4
- 0
model_zoo/official/lite/Himindspore/build.gradle View File

@@ -3,6 +3,9 @@ buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }

}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
@@ -16,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
}


+ 0
- 1
model_zoo/official/lite/Himindspore/imageObject/build.gradle View File

@@ -74,7 +74,6 @@ 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'



+ 1
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/.gitignore View File

@@ -0,0 +1 @@
/build

+ 66
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/build.gradle View File

@@ -0,0 +1,66 @@
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'
}
}
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
}

aaptOptions {
noCompress "ms"
}

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'
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'
}

+ 0
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/consumer-rules.pro View File


+ 57
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/download.gradle View File

@@ -0,0 +1,57 @@
/**
* 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 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 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
}


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)
}
}

+ 21
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/proguard-rules.pro View File

@@ -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

+ 26
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/src/androidTest/java/com/mindspore/mindsporelibrary/ExampleInstrumentedTest.java View File

@@ -0,0 +1,26 @@
package com.mindspore.mindsporelibrary;

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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.mindspore.mindsporelibrary.test", appContext.getPackageName());
}
}

+ 4
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/src/main/AndroidManifest.xml View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.mindspore.mindsporelibrary">

</manifest>

+ 17
- 0
model_zoo/official/lite/Himindspore/mindsporelibrary/src/test/java/com/mindspore/mindsporelibrary/ExampleUnitTest.java View File

@@ -0,0 +1,17 @@
package com.mindspore.mindsporelibrary;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}

+ 5
- 5
model_zoo/official/lite/Himindspore/posenet/build.gradle View File

@@ -5,13 +5,11 @@ plugins {
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
@@ -41,8 +39,11 @@ android {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }

flatDir {
dirs 'libs'
dirs 'libs', '../mindsporelibrary/libs'
}
}

@@ -61,11 +62,10 @@ 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'
implementation(name: 'mindspore-lite-1.0.1', ext: 'aar')
}

+ 0
- 39
model_zoo/official/lite/Himindspore/posenet/download.gradle View File

@@ -3,14 +3,8 @@
* 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 {
@@ -20,44 +14,11 @@ task downloadModelFile(type: DownloadUrlTask) {
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


+ 4
- 4
model_zoo/official/lite/Himindspore/posenet/src/main/AndroidManifest.xml View File

@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mindspore.posenet">

<application
tools:replace="android:label"
android:allowBackup="true"
android:label="@string/app_name"
android:label="@string/posenet_app_name"
android:supportsRtl="true">

<activity
android:name=".PosenetMainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">

</activity>
android:theme="@style/Theme.AppCompat.NoActionBar" />
</application>

</manifest>


+ 1
- 1
model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PoseNetFragment.java View File

@@ -135,7 +135,7 @@ public class PoseNetFragment extends Fragment {
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);
return inflater.inflate(R.layout.posenet_fragment_pose_net, container, false);
}

@Override


+ 2
- 2
model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java View File

@@ -87,7 +87,7 @@ public class PosenetMainActivity extends AppCompatActivity implements CameraData
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.posenet_activity_main);
addCameraFragment();
}

@@ -178,7 +178,7 @@ public class PosenetMainActivity extends AppCompatActivity implements CameraData
* Set the paint color and size.
*/
private void setPaint() {
paint.setColor(getResources().getColor(R.color.text_blue));
paint.setColor(getResources().getColor(R.color.posenet_text_blue));
paint.setTextSize(80.0f);
paint.setStrokeWidth(8.0f);
}


+ 0
- 30
model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable-v24/ic_launcher_foreground.xml View File

@@ -1,30 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/logo2.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable-xxhdpi/logo2.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/circle_bg.xml → model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_circle_bg.xml View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/ic_launcher_background.xml → model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_ic_launcher_background.xml View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/image.jpg → model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_image.jpg View File


BIN
model_zoo/official/lite/Himindspore/posenet/src/main/res/drawable/posenet_logo.png View File

Before After
Width: 227  |  Height: 170  |  Size: 9.4 kB

model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/activity_main.xml → model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/posenet_activity_main.xml View File

@@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context="com.mindspore.posenetdemo.MainActivity">
tools:context="com.mindspore.posenet.PosenetMainActivity">

<FrameLayout
android:id="@+id/container"

model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/fragment_pose_net.xml → model_zoo/official/lite/Himindspore/posenet/src/main/res/layout/posenet_fragment_pose_net.xml View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/posenet_ic_launcher.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/ic_launcher_round.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-hdpi/posenet_ic_launcher_round.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/posenet_ic_launcher.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/ic_launcher_round.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-mdpi/posenet_ic_launcher_round.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/posenet_ic_launcher.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/ic_launcher_round.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xhdpi/posenet_ic_launcher_round.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/posenet_ic_launcher.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/ic_launcher_round.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxhdpi/posenet_ic_launcher_round.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/posenet_ic_launcher.png View File


model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png → model_zoo/official/lite/Himindspore/posenet/src/main/res/mipmap-xxxhdpi/posenet_ic_launcher_round.png View File


+ 12
- 12
model_zoo/official/lite/Himindspore/posenet/src/main/res/values/colors.xml View File

@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="posenet_colorPrimary">#6200EE</color>
<color name="posenet_colorPrimaryDark">#3700B3</color>
<color name="posenet_colorAccent">#03DAC5</color>

<color name="mindspore_semi_transparent">#66000000</color>
<color name="posenet_mindspore_semi_transparent">#66000000</color>

<color name="white">#ffffff</color>
<color name="black">#000000</color>
<color name="gray">#A69D9D</color>
<color name="gray_btn">#424242</color>
<color name="posenet_white">#ffffff</color>
<color name="posenet_black">#000000</color>
<color name="posenet_gray">#A69D9D</color>
<color name="posenet_gray_btn">#424242</color>

<color name="text_blue">#6DA7FF</color>
<color name="text_yellow">#F8E71C</color>
<color name="text_orange">#FF844D</color>
<color name="text_green">#66B50A</color>
<color name="posenet_text_blue">#6DA7FF</color>
<color name="posenet_text_yellow">#F8E71C</color>
<color name="posenet_text_orange">#FF844D</color>
<color name="posenet_text_green">#66B50A</color>

</resources>

+ 2
- 2
model_zoo/official/lite/Himindspore/posenet/src/main/res/values/strings.xml View File

@@ -1,5 +1,5 @@
<resources>
<string name="app_name">PoseNetDemo</string>
<string name="posenet_app_name">PoseNetDemo</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="posenet_hello_blank_fragment">Hello blank fragment</string>
</resources>

+ 4
- 4
model_zoo/official/lite/Himindspore/posenet/src/main/res/values/styles.xml View File

@@ -1,10 +1,10 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="posenet_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimary">@color/posenet_colorPrimary</item>
<item name="colorPrimaryDark">@color/posenet_colorPrimaryDark</item>
<item name="colorAccent">@color/posenet_colorAccent</item>
</style>

</resources>

+ 1
- 0
model_zoo/official/lite/Himindspore/settings.gradle View File

@@ -1,3 +1,4 @@
include ':mindsporelibrary'
include ':imageObject'
include ':styletransfer'
include ':posenet'


+ 3
- 2
model_zoo/official/lite/Himindspore/styletransfer/build.gradle View File

@@ -46,7 +46,7 @@ android {
google()
jcenter()
flatDir {
dirs 'libs'
dirs 'libs', '../mindsporelibrary/libs'
}
}

@@ -63,7 +63,6 @@ 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'
@@ -75,5 +74,7 @@ dependencies {

implementation 'com.alibaba:arouter-api:1.2.1'
annotationProcessor 'com.alibaba:arouter-compiler:1.1.2'
implementation(name: 'mindspore-lite-1.0.1', ext: 'aar')


}

+ 0
- 39
model_zoo/official/lite/Himindspore/styletransfer/download.gradle View File

@@ -3,16 +3,10 @@
* 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 {
@@ -30,36 +24,6 @@ task downloadTransferModelFile(type: DownloadUrlTask) {
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
}
@@ -70,9 +34,6 @@ if (file("src/main/assets/style_predict_quant.ms").exists()) {

preBuild.dependsOn downloadPredictModelFile
preBuild.dependsOn downloadTransferModelFile
preBuild.dependsOn downloadMindSporeLibrary
preBuild.dependsOn unzipMindSporeInclude
preBuild.dependsOn cleanUnusedmindsporeFiles

class DownloadUrlTask extends DefaultTask {
@Input


+ 13
- 1
model_zoo/official/lite/Himindspore/styletransfer/src/main/AndroidManifest.xml View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mindspore.styletransfer">

<application
@@ -10,7 +11,18 @@
android:name=".StyleMainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
</application>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.mindspore.styletransfer.fileprovider"
android:exported="false"
tools:replace="android:authorities"
android:grantUriPermissions="true">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/style_file_paths" />
</provider>
</application>

</manifest>

+ 21
- 1
model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/BitmapUtils.java View File

@@ -89,7 +89,7 @@ public class BitmapUtils {
}

// Scale pictures to screen width.
private static Bitmap zoomImage(Bitmap imageBitmap, int targetWidth, int maxHeight) {
public static Bitmap zoomImage(Bitmap imageBitmap, int targetWidth, int maxHeight) {
float scaleFactor =
Math.max(
(float) imageBitmap.getWidth() / (float) targetWidth,
@@ -104,6 +104,26 @@ public class BitmapUtils {
return resizedBitmap;
}

public static Bitmap changeBitmapSize(Bitmap bitmap, int targetWidth, int targetHeight) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Log.e("width", "width:" + width);
Log.e("height", "height:" + height);

float scaleWidth = ((float) targetWidth) / width;
float scaleHeight = ((float) targetHeight) / height;

Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);

bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
bitmap.getWidth();
bitmap.getHeight();
Log.e("newWidth", "newWidth" + bitmap.getWidth());
Log.e("newHeight", "newHeight" + bitmap.getHeight());
return bitmap;
}

/**
* Get the rotation angle of the photo.
*


+ 65
- 0
model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/ImageUtils.java View File

@@ -16,16 +16,24 @@
package com.mindspore.styletransfer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -33,6 +41,8 @@ import java.nio.ByteOrder;

public class ImageUtils {

private static final String TAG = "ImageUtils";

private static Matrix decodeExifOrientation(int orientation) {
Matrix matrix = new Matrix();

@@ -198,4 +208,59 @@ public class ImageUtils {
}
return ret;
}

// Save the picture to the system album and refresh it.
public static void saveToAlbum(final Context context, Bitmap bitmap) {
File file = null;
String fileName = System.currentTimeMillis() + ".jpg";
File root = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), context.getPackageName());
File dir = new File(root, "image");
if (dir.mkdirs() || dir.isDirectory()) {
file = new File(dir, fileName);
}
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.flush();

} catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage());
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} finally {
try {
if (os != null) {
os.close();
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
}
if (file == null) {
return;
}
// Gallery refresh.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String path = null;
try {
path = file.getCanonicalPath();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
MediaScannerConnection.scanFile(context, new String[]{path}, null,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(uri);
context.sendBroadcast(mediaScanIntent);
}
});
} else {
String relationDir = file.getParent();
File file1 = new File(relationDir);
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(file1.getAbsoluteFile())));
}
}
}

+ 9
- 0
model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/OnBackgroundImageListener.java View File

@@ -0,0 +1,9 @@
package com.mindspore.styletransfer;

import android.view.View;

public interface OnBackgroundImageListener {
void onBackImageSelected(int position);

void onImageAdd(View view);
}

+ 0
- 5
model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/OnListFragmentInteractionListener.java View File

@@ -1,5 +0,0 @@
package com.mindspore.styletransfer;

public interface OnListFragmentInteractionListener {
void onListFragmentInteraction(String item);
}

+ 129
- 62
model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleMainActivity.java View File

@@ -18,44 +18,54 @@ package com.mindspore.styletransfer;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.File;
import java.io.FileNotFoundException;

@Route(path = "/styletransfer/StyleMainActivity")
public class StyleMainActivity extends AppCompatActivity implements View.OnClickListener, OnListFragmentInteractionListener {
public class StyleMainActivity extends AppCompatActivity implements OnBackgroundImageListener {

private static final String TAG = "StyleMainActivity";

private static final int[] IMAGES = {R.drawable.style0, R.drawable.style1, R.drawable.style2, R.drawable.style3, R.drawable.style4,
R.drawable.style5, R.drawable.style6, R.drawable.style7, R.drawable.style8, R.drawable.style9,
R.drawable.style10, R.drawable.style11, R.drawable.style12, R.drawable.style13, R.drawable.style14,
R.drawable.style15, R.drawable.style16, R.drawable.style17, R.drawable.style18, R.drawable.style19, R.drawable.add};

private static final int RC_CHOOSE_PHOTO = 1;
private static final int RC_CHOOSE_PHOTO_FOR_BACKGROUND = 11;
private static final int RC_CHOOSE_CAMERA = 2;


private StyleTransferModelExecutor transferModelExecutor;

private boolean isRunningModel;

private ImageView imgOrigin;
private Button btnImage;
private ImageView imgPreview;
private Uri imageUri;
private TextView textOriginImage;
private ProgressBar progressBar;

private RecyclerView recyclerView;

@@ -63,8 +73,7 @@ public class StyleMainActivity extends AppCompatActivity implements View.OnClick
private Integer maxHeightOfImage;
private boolean isLandScape;

private Bitmap originBitmap, styleBitmap;
private String selectedStyle;
private Bitmap originBitmap, styleBitmap, resultBitmap;

@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -75,52 +84,78 @@ public class StyleMainActivity extends AppCompatActivity implements View.OnClick
}

private void init() {
imgOrigin = findViewById(R.id.img_origin);
btnImage = findViewById(R.id.btn_image);
imgOrigin.setOnClickListener(this);
btnImage.setOnClickListener(this);

imgPreview = findViewById(R.id.img_origin);
textOriginImage = findViewById(R.id.tv_image);
progressBar = findViewById(R.id.progress);
recyclerView = findViewById(R.id.recyclerview);
List<String> styles = new ArrayList<>();
try {
styles.addAll(Arrays.asList(getAssets().list("thumbnails")));
} catch (IOException e) {
e.printStackTrace();
}

GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(new StyleRecyclerViewAdapter(this, styles, this));

recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
recyclerView.setAdapter(new StyleRecyclerViewAdapter(this, IMAGES, this));
transferModelExecutor = new StyleTransferModelExecutor(this, false);
}

public void onClickPhoto(View view) {
openGallay(RC_CHOOSE_PHOTO);
textOriginImage.setVisibility(View.GONE);
}

@Override
public void onClick(View view) {
if (view.getId() == R.id.img_origin || view.getId() == R.id.btn_image) {
btnImage.setVisibility(View.GONE);
openGallay();
public void onClickCamera(View view) {
openCamera();
textOriginImage.setVisibility(View.GONE);
}

public void onClickRecovery(View view) {
if (originBitmap != null) {
Glide.with(this).load(originBitmap).into(imgPreview);
} else {
Toast.makeText(this, "Please select an original picture first", Toast.LENGTH_SHORT).show();
}
}

public void onClickSave(View view) {
if (this.resultBitmap == null) {
Log.e(TAG, "null processed image");
Toast.makeText(this.getApplicationContext(), R.string.no_pic_neededSave, Toast.LENGTH_SHORT).show();
} else {
ImageUtils.saveToAlbum(getApplicationContext(), this.resultBitmap);
Toast.makeText(this.getApplicationContext(), R.string.save_success, Toast.LENGTH_SHORT).show();
}
}

private void openGallay() {
private void openGallay(int request) {
Intent intentToPickPic = new Intent(Intent.ACTION_PICK, null);
intentToPickPic.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
startActivityForResult(intentToPickPic, RC_CHOOSE_PHOTO);
startActivityForResult(intentToPickPic, request);
}

private void openCamera() {
Intent intentToTakePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String mTempPhotoPath = Environment.getExternalStorageDirectory() + File.separator + "photo.jpeg";
imageUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", new File(mTempPhotoPath));
intentToTakePhoto.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intentToTakePhoto, RC_CHOOSE_CAMERA);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (RC_CHOOSE_PHOTO == requestCode && null != data && null != data.getData()) {
if (data != null) {
this.imageUri = data.getData();
showOriginImage();
if (resultCode == RESULT_OK) {
if (RC_CHOOSE_PHOTO == requestCode) {
if (null != data && null != data.getData()) {
this.imageUri = data.getData();
showOriginImage();
} else {
finish();
}
} else if (RC_CHOOSE_PHOTO_FOR_BACKGROUND == requestCode) {
if (null != data && null != data.getData()) {
showCustomBack(data.getData());
} else {
finish();
}
} else if (RC_CHOOSE_CAMERA == requestCode) {
showOriginCamera();
}
} else {
finish();
}
}

@@ -128,49 +163,81 @@ public class StyleMainActivity extends AppCompatActivity implements View.OnClick
Pair<Integer, Integer> targetedSize = this.getTargetSize();
int targetWidth = targetedSize.first;
int maxHeight = targetedSize.second;
originBitmap = BitmapUtils.loadFromPath(StyleMainActivity.this, imageUri, targetWidth, maxHeight);
originBitmap = BitmapUtils.loadFromPath(this, imageUri, targetWidth, maxHeight);
// Determine how much to scale down the image.
Log.i(TAG, "resized image size width:" + originBitmap.getWidth() + ",height: " + originBitmap.getHeight());
Log.e(TAG, "resized image size width:" + originBitmap.getWidth() + ",height: " + originBitmap.getHeight());
if (originBitmap != null) {
Glide.with(this).load(originBitmap).into(imgPreview);
}
}

private void showOriginCamera() {
try {
Pair<Integer, Integer> targetedSize = this.getTargetSize();
int targetWidth = targetedSize.first;
int maxHeight = targetedSize.second;
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
originBitmap = BitmapUtils.zoomImage(bitmap, targetWidth, maxHeight);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Determine how much to scale down the image.
Log.e(TAG, "resized image size width:" + originBitmap.getWidth() + ",height: " + originBitmap.getHeight());
if (originBitmap != null) {
Glide.with(this).load(originBitmap).into(imgOrigin);
Glide.with(this).load(originBitmap).into(imgPreview);
}
}

private void showCustomBack(Uri imageUri) {
Pair<Integer, Integer> targetedSize = this.getTargetSize();
int targetWidth = targetedSize.first;
int maxHeight = targetedSize.second;
styleBitmap = BitmapUtils.loadFromPath(this, imageUri, targetWidth, maxHeight);
startRunningModel(styleBitmap);
}

@Override
public void onListFragmentInteraction(String item) {
this.selectedStyle = item;
startRunningModel();
public void onBackImageSelected(int position) {
styleBitmap = BitmapFactory.decodeResource(getResources(), IMAGES[position]);
startRunningModel(styleBitmap);
}

private void startRunningModel() {
if (!isRunningModel && !TextUtils.isEmpty(selectedStyle)) {
styleBitmap = ImageUtils.loadBitmapFromResources(this, getUriFromAssetThumb(selectedStyle));
if (originBitmap == null) {
Toast.makeText(this, "Please select an original picture first", Toast.LENGTH_SHORT).show();
return;
}
@Override
public void onImageAdd(View view) {
openGallay(RC_CHOOSE_PHOTO_FOR_BACKGROUND);
}

private void startRunningModel(Bitmap styleBitmap) {
if (originBitmap == null) {
Toast.makeText(this, "Please select an original picture first", Toast.LENGTH_SHORT).show();
return;
}

if (!isRunningModel) {
isRunningModel = true;
progressBar.setVisibility(View.VISIBLE);
ModelExecutionResult result = transferModelExecutor.execute(originBitmap, styleBitmap);
Glide.with(this).load(result.getStyledImage()).into(imgOrigin);
if (null != result && null != result.getStyledImage()) {
resultBitmap = BitmapUtils.changeBitmapSize(result.getStyledImage(), originBitmap.getWidth(), originBitmap.getHeight());
Log.e("AAA", "w>>" + resultBitmap.getWidth() + ">>>h>>" + resultBitmap.getHeight());
Glide.with(this).load(resultBitmap).override(resultBitmap.getWidth(), resultBitmap.getHeight()).into(imgPreview);
} else {
Toast.makeText(this, "ModelExecute failed", Toast.LENGTH_SHORT).show();
}
isRunningModel = false;
progressBar.setVisibility(View.INVISIBLE);
} else {
Toast.makeText(this, "Previous Model still running", Toast.LENGTH_SHORT).show();
}
}

private String getUriFromAssetThumb(String thumb) {
return "thumbnails/" + thumb;
}

// Returns max width of image.
private Integer getMaxWidthOfImage() {
if (this.maxWidthOfImage == null) {
if (this.isLandScape) {
this.maxWidthOfImage = ((View) this.imgOrigin.getParent()).getHeight();
this.maxWidthOfImage = ((View) this.imgPreview.getParent()).getHeight();
} else {
this.maxWidthOfImage = ((View) this.imgOrigin.getParent()).getWidth();
this.maxWidthOfImage = ((View) this.imgPreview.getParent()).getWidth();
}
}
return this.maxWidthOfImage;
@@ -180,9 +247,9 @@ public class StyleMainActivity extends AppCompatActivity implements View.OnClick
private Integer getMaxHeightOfImage() {
if (this.maxHeightOfImage == null) {
if (this.isLandScape) {
this.maxHeightOfImage = ((View) this.imgOrigin.getParent()).getWidth();
this.maxHeightOfImage = ((View) this.imgPreview.getParent()).getWidth();
} else {
this.maxHeightOfImage = ((View) this.imgOrigin.getParent()).getHeight();
this.maxHeightOfImage = ((View) this.imgPreview.getParent()).getHeight();
}
}
return this.maxHeightOfImage;


+ 17
- 31
model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleRecyclerViewAdapter.java View File

@@ -16,7 +16,6 @@
package com.mindspore.styletransfer;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -27,35 +26,16 @@ import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

public class StyleRecyclerViewAdapter extends RecyclerView.Adapter<StyleRecyclerViewAdapter.StyleItemViewHolder> {

private View.OnClickListener mOnClickListener;
private List<String> stylesList;
private Context context;
private OnListFragmentInteractionListener mListener;
private final int[] IMAGES;
private final Context context;
private final OnBackgroundImageListener mListener;

public StyleRecyclerViewAdapter(Context context, List<String> stylesList, OnListFragmentInteractionListener mListener) {
this.stylesList = stylesList;
public StyleRecyclerViewAdapter(Context context, int[] IMAGES, OnBackgroundImageListener mListener) {
this.IMAGES = IMAGES;
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
@@ -68,21 +48,27 @@ public class StyleRecyclerViewAdapter extends RecyclerView.Adapter<StyleRecycler

@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().
load(IMAGES[position]).
into(holder.getImageView());

View view = holder.getMView();
view.setTag(imagePath);
view.setOnClickListener(this.mOnClickListener);
view.setTag(IMAGES[position]);
view.setOnClickListener(view1 -> {
if (mListener != null) {
if (IMAGES.length - 1 == position) {
mListener.onImageAdd(holder.getImageView());
} else {
mListener.onBackImageSelected(position);
}
}
});
}


@Override
public int getItemCount() {
return stylesList == null ? 0 : stylesList.size();
return IMAGES == null ? 0 : IMAGES.length;
}




+ 0
- 15
model_zoo/official/lite/Himindspore/styletransfer/src/main/java/com/mindspore/styletransfer/StyleTransferModelExecutor.java View File

@@ -113,8 +113,6 @@ public class StyleTransferModelExecutor {


/**
* float 数组转 byte数组.
*
* @param floats the floats
* @return the byte [ ]
*/
@@ -127,23 +125,15 @@ public class StyleTransferModelExecutor {
}

@SuppressLint("LongLogTag")
// public ModelExecutionResult execute(String contentImagePath, String styleImageName) {
public ModelExecutionResult execute(Bitmap contentImage, Bitmap styleBitmap) {
Log.i(TAG, "running models");

fullExecutionTime = SystemClock.uptimeMillis();
preProcessTime = SystemClock.uptimeMillis();

// Bitmap contentImage = ImageUtils.decodeBitmap(new File(contentImagePath));
ByteBuffer contentArray =
ImageUtils.bitmapToByteBuffer(contentImage, CONTENT_IMAGE_SIZE, CONTENT_IMAGE_SIZE, 0, 255);


// Bitmap styleBitmap =
// ImageUtils.loadBitmapFromResources(context, "thumbnails/" + styleImageName);
ByteBuffer input = ImageUtils.bitmapToByteBuffer(styleBitmap, STYLE_IMAGE_SIZE, STYLE_IMAGE_SIZE, 0, 255);


List<MSTensor> Predict_inputs = Predict_session.getInputs();
if (Predict_inputs.size() != 1) {
return null;
@@ -154,7 +144,6 @@ public class StyleTransferModelExecutor {
preProcessTime = SystemClock.uptimeMillis() - preProcessTime;
stylePredictTime = SystemClock.uptimeMillis();


if (!Predict_session.runGraph()) {
Log.e("MS_LITE", "Run Predict_graph failed");
return null;
@@ -186,8 +175,6 @@ public class StyleTransferModelExecutor {

MSTensor Transform_inputs_inTensor1 = Transform_inputs.get(1);
Transform_inputs_inTensor1.setData(contentArray);


styleTransferTime = SystemClock.uptimeMillis();

if (!Transform_session.runGraph()) {
@@ -197,7 +184,6 @@ public class StyleTransferModelExecutor {

styleTransferTime = SystemClock.uptimeMillis() - styleTransferTime;
Log.d(TAG, "Style apply Time to run: " + styleTransferTime);

postProcessTime = SystemClock.uptimeMillis();

// Get output tensor values.
@@ -232,7 +218,6 @@ public class StyleTransferModelExecutor {
outputImage[x] = arrayThree;
}


Bitmap styledImage =
ImageUtils.convertArrayToBitmap(outputImage, CONTENT_IMAGE_SIZE, CONTENT_IMAGE_SIZE);
postProcessTime = SystemClock.uptimeMillis() - postProcessTime;


BIN
model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/add.jpg View File

Before After
Width: 648  |  Height: 649  |  Size: 19 kB

model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style0.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style0.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style1.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style1.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style10.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style10.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style11.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style11.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style12.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style12.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style13.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style13.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style14.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style14.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style15.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style15.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style16.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style16.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style17.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style17.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style18.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style18.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style19.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style19.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style2.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style2.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style20.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style20.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style3.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style3.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style4.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style4.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style5.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style5.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style6.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style6.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style7.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style7.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style8.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style8.jpg View File


model_zoo/official/lite/Himindspore/styletransfer/src/main/assets/thumbnails/style9.jpg → model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style9.jpg View File


BIN
model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable-xxhdpi/style_chose.png View File

Before After
Width: 662  |  Height: 645  |  Size: 982 kB

+ 20
- 0
model_zoo/official/lite/Himindspore/styletransfer/src/main/res/drawable/progressbar.xml View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false">
<gradient
android:centerColor="#62AEEC"
android:centerY="0.50"
android:endColor="#1063A5"
android:startColor="#61C2EC"
android:type="sweep"
android:useLevel="false" />
</shape>
</animated-rotate>

+ 86
- 10
model_zoo/official/lite/Himindspore/styletransfer/src/main/res/layout/activity_main_style.xml View File

@@ -18,6 +18,7 @@
android:drawableStart="@drawable/logo2"
android:drawablePadding="5dp"
android:gravity="center_vertical"
android:maxLines="1"
android:text="MindSpore StyleTransfer"
android:textColor="#ffffff"
android:textSize="20sp" />
@@ -25,42 +26,117 @@

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="300dp">

<ImageView
android:id="@+id/img_origin"
android:layout_width="256dp"
android:layout_height="256dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:scaleType="fitXY" />

<Button
android:id="@+id/btn_image"
<TextView
android:id="@+id/tv_image"
android:layout_width="206dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="@color/gray_btn"
android:gravity="center"
android:paddingLeft="4dp"
android:text="Choose a Image"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="16sp" />

android:textSize="20sp" />

<ProgressBar
android:id="@+id/progress"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/progressbar"
android:visibility="invisible" />
</FrameLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@color/gray_btn"
android:gravity="center"
android:onClick="onClickPhoto"
android:text="PHOTO"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="12sp" />

<Button
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@color/gray_btn"
android:gravity="center"
android:onClick="onClickCamera"
android:text="CAMERA"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="12sp" />

<Button
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@color/gray_btn"
android:gravity="center"
android:onClick="onClickRecovery"
android:text="RECOVERY"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="12sp" />

<Button
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:background="@color/gray_btn"
android:gravity="center"
android:onClick="onClickSave"
android:text="SAVE"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="Choose a Style"
android:textColor="@color/white"
android:textSize="20sp" />

<androidx.recyclerview.widget.RecyclerView
android:layout_margin="20dp"
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fadeScrollbars="false"
android:scrollbarSize="6dp"
android:scrollbarStyle="outsideInset"
android:scrollbarThumbVertical="@color/gray"
android:scrollbars="vertical" />
</LinearLayout>

+ 6
- 13
model_zoo/official/lite/Himindspore/styletransfer/src/main/res/layout/image_item.xml View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -8,14 +7,8 @@

<ImageView
android:id="@+id/image_view"
android:layout_width="150dp"
android:layout_height="150dp"
android:padding="0dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="W,1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_width="wrap_content"
android:layout_height="120dp"
android:scaleType="fitXY"
tools:srcCompat="@drawable/logo2" />
</LinearLayout>

+ 2
- 1
model_zoo/official/lite/Himindspore/styletransfer/src/main/res/values/strings.xml View File

@@ -1,5 +1,6 @@
<resources>
<string name="app_name">StyleTransfer</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="no_pic_neededSave">Null Image needed to save</string>
<string name="save_success">Save success</string>
</resources>

+ 6
- 0
model_zoo/official/lite/Himindspore/styletransfer/src/main/res/xml/style_file_paths.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files"
path="." />
</paths>

+ 5
- 5
model_zoo/official/lite/posenet/app/src/main/AndroidManifest.xml View File

@@ -17,16 +17,16 @@
<activity android:name=".TestActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">

</activity>
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">

</activity>
</application>

</manifest>

+ 1
- 1
model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java View File

@@ -172,7 +172,7 @@ public class Posenet {
* returns:
* person: a Person object containing data about keypoint locations and confidence scores
*/
Person estimateSinglePose(Bitmap bitmap) {
public Person estimateSinglePose(Bitmap bitmap) {
long estimationStartTimeNanos = SystemClock.elapsedRealtimeNanos();
ByteBuffer inputArray = this.initInputArray(bitmap);
List<MSTensor> inputs = session.getInputs();


Loading…
Cancel
Save