diff --git a/model_zoo/official/lite/posenet/app/build.gradle b/model_zoo/official/lite/posenet/app/build.gradle
index 9d57898096..59aed1eb06 100644
--- a/model_zoo/official/lite/posenet/app/build.gradle
+++ b/model_zoo/official/lite/posenet/app/build.gradle
@@ -46,7 +46,7 @@ android {
apply from:'download.gradle'
dependencies {
- implementation fileTree(dir: "libs", include: ["*.jar"])
+ implementation fileTree(dir: "libs", include: ["*.aar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
@@ -54,6 +54,4 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
- implementation(name: 'mindspore-lite-1.0.1', ext: 'aar')
-
}
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/.gitignore b/model_zoo/official/lite/style_transfer/.gitignore
new file mode 100644
index 0000000000..603b140773
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/.gitignore
@@ -0,0 +1,14 @@
+*.iml
+.gradle
+/local.properties
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+.cxx
diff --git a/model_zoo/official/lite/style_transfer/app/.gitignore b/model_zoo/official/lite/style_transfer/app/.gitignore
new file mode 100644
index 0000000000..42afabfd2a
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/build.gradle b/model_zoo/official/lite/style_transfer/app/build.gradle
new file mode 100644
index 0000000000..c6862e60bc
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/build.gradle
@@ -0,0 +1,62 @@
+apply plugin: 'com.android.application'
+apply from: 'download.gradle'
+
+android {
+ compileSdkVersion 30
+ buildToolsVersion "30.0.1"
+
+ defaultConfig {
+ applicationId "com.mindspore.styletransferdemo"
+ minSdkVersion 21
+ targetSdkVersion 30
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ }
+
+ 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
+ }
+}
+
+
+dependencies {
+ implementation fileTree(dir: "libs", include: ["*.aar"])
+ implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+ implementation 'androidx.recyclerview:recyclerview:1.1.0'
+
+ 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'
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/download.gradle b/model_zoo/official/lite/style_transfer/app/download.gradle
new file mode 100644
index 0000000000..4579bea792
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/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/style_transfer/app/proguard-rules.pro b/model_zoo/official/lite/style_transfer/app/proguard-rules.pro
new file mode 100644
index 0000000000..481bb43481
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/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/style_transfer/app/src/androidTest/java/com/mindspore/styletransferdemo/ExampleInstrumentedTest.java b/model_zoo/official/lite/style_transfer/app/src/androidTest/java/com/mindspore/styletransferdemo/ExampleInstrumentedTest.java
new file mode 100644
index 0000000000..ae02b983af
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/androidTest/java/com/mindspore/styletransferdemo/ExampleInstrumentedTest.java
@@ -0,0 +1,26 @@
+package com.mindspore.styletransferdemo;
+
+import android.content.Context;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * 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.styletransferdemo", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/AndroidManifest.xml b/model_zoo/official/lite/style_transfer/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..ae1416f3e8
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/AndroidManifest.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style0.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style0.jpg
new file mode 100644
index 0000000000..574f3e946e
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style0.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style1.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style1.jpg
new file mode 100644
index 0000000000..5f02c9ef41
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style1.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style2.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style2.jpg
new file mode 100644
index 0000000000..25aa42e400
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style2.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style3.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style3.jpg
new file mode 100644
index 0000000000..744137cc5d
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style3.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style4.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style4.jpg
new file mode 100644
index 0000000000..6ab1e43c93
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style4.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style5.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style5.jpg
new file mode 100644
index 0000000000..2fcfa07c2a
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style5.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style6.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style6.jpg
new file mode 100644
index 0000000000..2cc97b3038
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style6.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style7.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style7.jpg
new file mode 100644
index 0000000000..c34586d132
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style7.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style8.jpg b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style8.jpg
new file mode 100644
index 0000000000..e2ab318a06
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/assets/thumbnails/style8.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/BitmapUtils.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/BitmapUtils.java
new file mode 100644
index 0000000000..c8b2e3384c
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/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
+ *
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+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/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/ImageUtils.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/ImageUtils.java
new file mode 100644
index 0000000000..6bffde0db0
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/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
+ *
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+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/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/MainActivity.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/MainActivity.java
new file mode 100644
index 0000000000..9156890a7e
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/MainActivity.java
@@ -0,0 +1,223 @@
+/**
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+import android.Manifest;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.MediaStore;
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.Pair;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+
+import com.bumptech.glide.Glide;
+
+public class MainActivity extends AppCompatActivity implements View.OnClickListener, StyleFragment.OnListFragmentInteractionListener {
+
+ private static final String TAG = "MainActivity";
+
+ private static final int REQUEST_PERMISSION = 1;
+ private static final int RC_CHOOSE_PHOTO = 2;
+
+ private StyleTransferModelExecutor transferModelExecutor;
+
+ private boolean isHasPermssion;
+ private boolean isRunningModel;
+
+ private ImageView imgOrigin, imgStyle, imgResult;
+ private ProgressBar progressResult;
+ private Uri imageUri;
+
+ private Integer maxWidthOfImage;
+ private Integer maxHeightOfImage;
+ private boolean isLandScape;
+
+ private Bitmap originBitmap, styleBitmap;
+ private StyleFragment styleFragment;
+ private String selectedStyle;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ this.isLandScape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
+ requestPermissions();
+ init();
+ }
+
+ private void init() {
+ imgOrigin = findViewById(R.id.img_origin);
+ imgStyle = findViewById(R.id.img_style);
+ imgResult = findViewById(R.id.img_result);
+ progressResult = findViewById(R.id.progress_circular);
+
+ imgOrigin.setOnClickListener(this);
+ imgStyle.setOnClickListener(this);
+ imgResult.setOnClickListener(this);
+
+ styleFragment = StyleFragment.newInstance();
+ transferModelExecutor = new StyleTransferModelExecutor(this, false);
+ }
+
+ 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);
+ }
+
+ /**
+ * Authority application result callback
+ */
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ if (REQUEST_PERMISSION == requestCode) {
+ isHasPermssion = true;
+ }
+ }
+
+
+ @Override
+ public void onClick(View view) {
+ if (view.getId() == R.id.img_origin) {
+ if (isHasPermssion) {
+ openGallay();
+ } else {
+ requestPermissions();
+ }
+ } else if (view.getId() == R.id.img_style) {
+ if (!isRunningModel) {
+ styleFragment.show(getSupportFragmentManager(), TAG);
+ }
+ }
+ }
+
+ private void openGallay() {
+ Intent intentToPickPic = new Intent(Intent.ACTION_PICK, null);
+ intentToPickPic.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
+ startActivityForResult(intentToPickPic, RC_CHOOSE_PHOTO);
+ }
+
+ @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();
+ }
+ } else {
+ finish();
+ }
+ }
+
+ private void showOriginImage() {
+ Pair targetedSize = this.getTargetSize();
+ int targetWidth = targetedSize.first;
+ int maxHeight = targetedSize.second;
+ originBitmap = BitmapUtils.loadFromPath(MainActivity.this, imageUri, targetWidth, maxHeight);
+ // Determine how much to scale down the image.
+ Log.i(TAG, "resized image size width:" + originBitmap.getWidth() + ",height: " + originBitmap.getHeight());
+
+ if (originBitmap != null) {
+ Glide.with(this).load(originBitmap).into(imgOrigin);
+ }
+ }
+
+
+ @Override
+ public void onListFragmentInteraction(String item) {
+ this.selectedStyle = item;
+ styleFragment.dismiss();
+ startRunningModel();
+ }
+
+ private void startRunningModel() {
+ if (!isRunningModel && !TextUtils.isEmpty(selectedStyle)) {
+ styleBitmap = ImageUtils.loadBitmapFromResources(this, getUriFromAssetThumb(selectedStyle));
+ Glide.with(this)
+ .load(styleBitmap)
+ .into(imgStyle);
+
+ if (originBitmap == null) {
+ Toast.makeText(this, "Please select an original picture first", Toast.LENGTH_SHORT).show();
+ return;
+ }
+ progressResult.setVisibility(View.VISIBLE);
+ isRunningModel = true;
+ ModelExecutionResult result = transferModelExecutor.execute(originBitmap, styleBitmap);
+ Glide.with(this).load(result.getStyledImage()).into(imgResult);
+ progressResult.setVisibility(View.GONE);
+ isRunningModel = false;
+ } 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();
+ } else {
+ this.maxWidthOfImage = ((View) this.imgOrigin.getParent()).getWidth();
+ }
+ }
+ return this.maxWidthOfImage;
+ }
+
+ // Returns max height of image.
+ private Integer getMaxHeightOfImage() {
+ if (this.maxHeightOfImage == null) {
+ if (this.isLandScape) {
+ this.maxHeightOfImage = ((View) this.imgOrigin.getParent()).getWidth();
+ } else {
+ this.maxHeightOfImage = ((View) this.imgOrigin.getParent()).getHeight();
+ }
+ }
+ return this.maxHeightOfImage;
+ }
+
+ // Gets the targeted size(width / height).
+ private Pair getTargetSize() {
+ Integer targetWidth;
+ Integer targetHeight;
+ Integer maxWidth = this.getMaxWidthOfImage();
+ Integer maxHeight = this.getMaxHeightOfImage();
+ targetWidth = this.isLandScape ? maxHeight : maxWidth;
+ targetHeight = this.isLandScape ? maxWidth : maxHeight;
+ Log.i(TAG, "height:" + targetHeight + ",width:" + targetWidth);
+ return new Pair<>(targetWidth, targetHeight);
+ }
+
+
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/ModelExecutionResult.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/ModelExecutionResult.java
new file mode 100644
index 0000000000..0e8744a82b
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/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
+ *
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+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/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleFragment.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleFragment.java
new file mode 100644
index 0000000000..5171d14c05
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleFragment.java
@@ -0,0 +1,92 @@
+/**
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.DialogFragment;
+import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Use the {@link StyleFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class StyleFragment extends DialogFragment {
+
+ private OnListFragmentInteractionListener listener;
+
+ public StyleFragment() {
+ // Required empty public constructor
+ }
+
+
+ public static StyleFragment newInstance() {
+ StyleFragment fragment = new StyleFragment();
+ return fragment;
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_style, container, false);
+ List styles = new ArrayList<>();
+ try {
+ styles.addAll(Arrays.asList(getActivity().getAssets().list("thumbnails")));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ if (view instanceof RecyclerView) {
+ GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3);
+ ((RecyclerView) view).setLayoutManager(gridLayoutManager);
+ ((RecyclerView) view).setAdapter(new StyleRecyclerViewAdapter(getActivity(), styles, listener));
+ }
+
+ return view;
+ }
+
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ if (context instanceof OnListFragmentInteractionListener) {
+ this.listener = (StyleFragment.OnListFragmentInteractionListener) context;
+ }
+ }
+
+ public void onDetach() {
+ super.onDetach();
+ this.listener = null;
+ }
+
+ public interface OnListFragmentInteractionListener {
+ void onListFragmentInteraction(String item);
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleRecyclerViewAdapter.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleRecyclerViewAdapter.java
new file mode 100644
index 0000000000..523be83177
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleRecyclerViewAdapter.java
@@ -0,0 +1,111 @@
+/**
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+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 StyleFragment.OnListFragmentInteractionListener mListener;
+
+ public StyleRecyclerViewAdapter(Context context, List stylesList, StyleFragment.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/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/StyleTransferModelExecutor.java
new file mode 100644
index 0000000000..b3e771d3c2
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/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
+ *
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.os.SystemClock;
+import android.util.Log;
+
+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.nio.FloatBuffer;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class StyleTransferModelExecutor {
+
+ private static final String TAG = "StyleTransferModelExecutor";
+ private static final int STYLE_IMAGE_SIZE = 256;
+ private static final int CONTENT_IMAGE_SIZE = 384;
+
+ private Context mContext;
+
+ private MSConfig msConfig;
+ private LiteSession Predict_session;
+ private LiteSession Transform_session;
+ private Model style_predict_model;
+ private Model style_transform_model;
+ private LinkedHashMap mOutputs;
+
+ private long fullExecutionTime;
+ private long preProcessTime;
+ private long stylePredictTime;
+ private long styleTransferTime;
+ private long postProcessTime;
+
+ private final int NUM_THREADS = 4;
+
+ public StyleTransferModelExecutor(Context context, boolean useGPU) {
+ mContext = context;
+ init();
+ }
+
+ public void init() {
+ // Load the .ms model.
+ style_predict_model = new Model();
+ if (!style_predict_model.loadModel(mContext, "style_predict_quant.ms")) {
+ Log.e("MS_LITE", "Load style_predict_model failed");
+ }
+
+ style_transform_model = new Model();
+ if (!style_transform_model.loadModel(mContext, "style_transfer_quant.ms")) {
+ Log.e("MS_LITE", "Load style_transform_model failed");
+ }
+ // 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");
+ }
+
+ // Create the MindSpore lite session.
+ Predict_session = new LiteSession();
+ if (!Predict_session.init(msConfig)) {
+ Log.e("MS_LITE", "Create Predict_session failed");
+ msConfig.free();
+ }
+
+ Transform_session = new LiteSession();
+ if (!Transform_session.init(msConfig)) {
+ Log.e("MS_LITE", "Create Predict_session failed");
+ msConfig.free();
+ }
+ msConfig.free();
+
+
+ // Complile graph.
+ if (!Predict_session.compileGraph(style_predict_model)) {
+ Log.e("MS_LITE", "Compile style_predict graph failed");
+ style_predict_model.freeBuffer();
+ }
+ if (!Transform_session.compileGraph(style_transform_model)) {
+ Log.e("MS_LITE", "Compile style_transform graph failed");
+ style_transform_model.freeBuffer();
+ }
+
+ // Note: when use model.freeBuffer(), the model can not be complile graph again.
+ style_predict_model.freeBuffer();
+ style_transform_model.freeBuffer();
+ }
+
+
+ /**
+ * float 数组转 byte数组.
+ *
+ * @param floats the floats
+ * @return the byte [ ]
+ */
+ public static byte[] floatArrayToByteArray(float[] floats) {
+ ByteBuffer buffer = ByteBuffer.allocate(4 * floats.length);
+ buffer.order(ByteOrder.nativeOrder());
+ FloatBuffer floatBuffer = buffer.asFloatBuffer();
+ floatBuffer.put(floats);
+ return buffer.array();
+ }
+
+ @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 Predict_inputs = Predict_session.getInputs();
+ if (Predict_inputs.size() != 1) {
+ return null;
+ }
+ MSTensor Predict_inTensor = Predict_inputs.get(0);
+ Predict_inTensor.setData(input);
+
+ preProcessTime = SystemClock.uptimeMillis() - preProcessTime;
+ stylePredictTime = SystemClock.uptimeMillis();
+
+
+ if (!Predict_session.runGraph()) {
+ Log.e("MS_LITE", "Run Predict_graph failed");
+ return null;
+ }
+ stylePredictTime = SystemClock.uptimeMillis() - stylePredictTime;
+ Log.d(TAG, "Style Predict Time to run: " + stylePredictTime);
+
+ // Get output tensor values.
+ List tensorNames = Predict_session.getOutputTensorNames();
+ Map outputs = Predict_session.getOutputMapByTensor();
+ Set> entrys = outputs.entrySet();
+
+ float[] Predict_results = null;
+ for (String tensorName : tensorNames) {
+ MSTensor output = outputs.get(tensorName);
+ if (output == null) {
+ Log.e("MS_LITE", "Can not find Predict_session output " + tensorName);
+ return null;
+ }
+ int type = output.getDataType();
+ Predict_results = output.getFloatData();
+ }
+
+
+ List Transform_inputs = Transform_session.getInputs();
+ // transform model have 2 input tensor, tensor0: 1*1*1*100, tensor1;1*384*384*3
+ MSTensor Transform_inputs_inTensor0 = Transform_inputs.get(0);
+ Transform_inputs_inTensor0.setData(floatArrayToByteArray(Predict_results));
+
+ MSTensor Transform_inputs_inTensor1 = Transform_inputs.get(1);
+ Transform_inputs_inTensor1.setData(contentArray);
+
+
+ styleTransferTime = SystemClock.uptimeMillis();
+
+ if (!Transform_session.runGraph()) {
+ Log.e("MS_LITE", "Run Transform_graph failed");
+ return null;
+ }
+
+ styleTransferTime = SystemClock.uptimeMillis() - styleTransferTime;
+ Log.d(TAG, "Style apply Time to run: " + styleTransferTime);
+
+ postProcessTime = SystemClock.uptimeMillis();
+
+ // Get output tensor values.
+ List Transform_tensorNames = Transform_session.getOutputTensorNames();
+ Map Transform_outputs = Transform_session.getOutputMapByTensor();
+
+ float[] transform_results = null;
+ for (String tensorName : Transform_tensorNames) {
+ MSTensor output1 = Transform_outputs.get(tensorName);
+ if (output1 == null) {
+ Log.e("MS_LITE", "Can not find Transform_session output " + tensorName);
+ return null;
+ }
+ transform_results = output1.getFloatData();
+ }
+
+ float[][][][] outputImage = new float[1][][][]; // 1 384 384 3
+ for (int x = 0; x < 1; x++) {
+ float[][][] arrayThree = new float[CONTENT_IMAGE_SIZE][][];
+ for (int y = 0; y < CONTENT_IMAGE_SIZE; y++) {
+ float[][] arrayTwo = new float[CONTENT_IMAGE_SIZE][];
+ for (int z = 0; z < CONTENT_IMAGE_SIZE; z++) {
+ float[] arrayOne = new float[3];
+ for (int i = 0; i < 3; i++) {
+ int n = i + z * 3 + y * CONTENT_IMAGE_SIZE * 3 + x * CONTENT_IMAGE_SIZE * CONTENT_IMAGE_SIZE * 3;
+ arrayOne[i] = transform_results[n];
+ }
+ arrayTwo[z] = arrayOne;
+ }
+ arrayThree[y] = arrayTwo;
+ }
+ outputImage[x] = arrayThree;
+ }
+
+
+ Bitmap styledImage =
+ ImageUtils.convertArrayToBitmap(outputImage, CONTENT_IMAGE_SIZE, CONTENT_IMAGE_SIZE);
+ postProcessTime = SystemClock.uptimeMillis() - postProcessTime;
+
+ fullExecutionTime = SystemClock.uptimeMillis() - fullExecutionTime;
+ Log.d(TAG, "Time to run everything: $" + fullExecutionTime);
+
+ return new ModelExecutionResult(styledImage,
+ preProcessTime,
+ stylePredictTime,
+ styleTransferTime,
+ postProcessTime,
+ fullExecutionTime,
+ formatExecutionLog());
+ }
+
+
+ private String formatExecutionLog() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Input Image Size:" + CONTENT_IMAGE_SIZE * CONTENT_IMAGE_SIZE)
+ .append("\nPre-process execution time: " + preProcessTime + " ms")
+ .append("\nPredicting style execution time: " + stylePredictTime + " ms")
+ .append("\nTransferring style execution time: " + styleTransferTime + " ms")
+ .append("\nPost-process execution time: " + postProcessTime + " ms")
+ .append("\nFull execution time: " + fullExecutionTime + " ms");
+ return sb.toString();
+ }
+
+}
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/TestActivity.java b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/TestActivity.java
new file mode 100644
index 0000000000..72e61399b8
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/java/com/mindspore/styletransferdemo/TestActivity.java
@@ -0,0 +1,52 @@
+/**
+ * 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.
+ */
+package com.mindspore.styletransferdemo;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.widget.ImageView;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.bumptech.glide.Glide;
+
+public class TestActivity extends AppCompatActivity {
+
+ private ImageView img1, img2, img3;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_test);
+
+ img1 = findViewById(R.id.img1);
+ img2 = findViewById(R.id.img2);
+ img3 = findViewById(R.id.img3);
+
+ Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.person);
+ Glide.with(this).load(bitmap1).into(img1);
+
+ Bitmap bitmap2 =
+ ImageUtils.loadBitmapFromResources(this, "thumbnails/style3.jpg");
+ Glide.with(this).load(bitmap2).into(img2);
+
+
+ StyleTransferModelExecutor transferModelExecutor = new StyleTransferModelExecutor(this, false);
+ ModelExecutionResult result = transferModelExecutor.execute(bitmap1, bitmap2);
+ Glide.with(this).load(result.getStyledImage()).into(img3);
+ }
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 0000000000..2b068d1146
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/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/style_transfer/app/src/main/res/drawable-xxhdpi/logo2.png b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/logo2.png
new file mode 100644
index 0000000000..c90f1dda43
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/logo2.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/style_chose.png b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/style_chose.png
new file mode 100644
index 0000000000..932fe3df2e
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/style_chose.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/theme.jpg b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/theme.jpg
new file mode 100644
index 0000000000..3827ee52aa
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable-xxhdpi/theme.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/drawable/ic_launcher_background.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000000..07d5da9cbf
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/drawable/person.jpg b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable/person.jpg
new file mode 100644
index 0000000000..ca6c98e164
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/drawable/person.jpg differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/layout/activity_main.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000000..1fb47efc49
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/layout/activity_test.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/activity_test.xml
new file mode 100644
index 0000000000..1dff72e70b
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/activity_test.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/layout/fragment_style.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/fragment_style.xml
new file mode 100644
index 0000000000..c32f2fbd01
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/fragment_style.xml
@@ -0,0 +1,16 @@
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/layout/image_item.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/image_item.xml
new file mode 100644
index 0000000000..fd570e2a2d
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/layout/image_item.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000000..eca70cfe52
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 0000000000..eca70cfe52
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-hdpi/ic_launcher.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000000..a571e60098
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 0000000000..61da551c55
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-mdpi/ic_launcher.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000000..c41dd28531
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 0000000000..db5080a752
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000000..6dba46dab1
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 0000000000..da31a871c8
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000000..15ac681720
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000000..b216f2d313
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000000..f25a419744
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000000..e96783ccce
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/values/colors.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000000..f703aee532
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/values/colors.xml
@@ -0,0 +1,16 @@
+
+
+ #6200EE
+ #3700B3
+ #03DAC5
+
+ #ffffff
+ #000000
+ #A69D9D
+ #424242
+
+ #6DA7FF
+ #F8E71C
+ #FF844D
+ #66B50A
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/values/strings.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000000..6c6166bf55
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+ StyleTransfer
+
+ Hello blank fragment
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/main/res/values/styles.xml b/model_zoo/official/lite/style_transfer/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000000..13f74a4612
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/main/res/values/styles.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/app/src/test/java/com/mindspore/styletransferdemo/ExampleUnitTest.java b/model_zoo/official/lite/style_transfer/app/src/test/java/com/mindspore/styletransferdemo/ExampleUnitTest.java
new file mode 100644
index 0000000000..9c9807b1a3
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/app/src/test/java/com/mindspore/styletransferdemo/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.mindspore.styletransferdemo;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * 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/style_transfer/build.gradle b/model_zoo/official/lite/style_transfer/build.gradle
new file mode 100644
index 0000000000..6754c23d52
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/build.gradle
@@ -0,0 +1,24 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+ repositories {
+ google()
+ jcenter()
+ }
+ dependencies {
+ classpath "com.android.tools.build:gradle:4.0.1"
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
\ No newline at end of file
diff --git a/model_zoo/official/lite/style_transfer/gradle.properties b/model_zoo/official/lite/style_transfer/gradle.properties
new file mode 100644
index 0000000000..c52ac9b797
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/gradle.properties
@@ -0,0 +1,19 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx2048m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app"s APK
+# 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
diff --git a/model_zoo/official/lite/style_transfer/gradle/wrapper/gradle-wrapper.jar b/model_zoo/official/lite/style_transfer/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000000..f6b961fd5a
Binary files /dev/null and b/model_zoo/official/lite/style_transfer/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/model_zoo/official/lite/style_transfer/gradle/wrapper/gradle-wrapper.properties b/model_zoo/official/lite/style_transfer/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000000..8165678aad
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Nov 13 16:47:23 CST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
diff --git a/model_zoo/official/lite/style_transfer/gradlew b/model_zoo/official/lite/style_transfer/gradlew
new file mode 100644
index 0000000000..cccdd3d517
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/model_zoo/official/lite/style_transfer/gradlew.bat b/model_zoo/official/lite/style_transfer/gradlew.bat
new file mode 100644
index 0000000000..f9553162f1
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/model_zoo/official/lite/style_transfer/settings.gradle b/model_zoo/official/lite/style_transfer/settings.gradle
new file mode 100644
index 0000000000..3260a2ea14
--- /dev/null
+++ b/model_zoo/official/lite/style_transfer/settings.gradle
@@ -0,0 +1,2 @@
+include ':app'
+rootProject.name = "StyleTransferDemo"
\ No newline at end of file