-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
406 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2019 The AoE Authors. All Rights Reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
|
||
ext { | ||
releaseArtifact = 'extensions-tensorflow-lite' | ||
releaseDescription = 'The AoE tensorflow lite extensions library' | ||
releaseVersion = aoe_version_name | ||
} | ||
apply from: rootProject.file('gradle/release.gradle') | ||
|
||
android { | ||
compileSdkVersion aoe_compile_sdk_version | ||
defaultConfig { | ||
minSdkVersion aoe_min_sdk_version | ||
targetSdkVersion aoe_target_sdk_version | ||
versionName releaseVersion | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation deps.support.annotation | ||
|
||
implementation deps.aoe.library.core | ||
|
||
implementation deps.kotlin | ||
|
||
implementation 'org.tensorflow:tensorflow-lite:2.0.0' | ||
implementation 'org.tensorflow:tensorflow-lite-gpu:2.0.0' | ||
|
||
implementation deps.aoe.runtime.tensorflow | ||
|
||
} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
18 changes: 18 additions & 0 deletions
18
Android/extensions/tensorflow-lite/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
~ Copyright 2019 The AoE Authors. All Rights Reserved. | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.didi.aoe.extensions.tensorflow.lite" /> |
39 changes: 39 additions & 0 deletions
39
...xtensions/tensorflow-lite/src/main/java/com/didi/aoe/extensions/tensorflow/lite/AoeExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2019 The AoE Authors. All Rights Reserved. | ||
* | ||
* 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.didi.aoe.extensions.tensorflow.lite | ||
|
||
import android.content.Context | ||
import com.didi.aoe.library.api.Aoe | ||
import com.didi.aoe.library.core.AoeClient | ||
import com.didi.aoe.runtime.tensorflow.lite.TensorFlowMultipleInputsOutputsInterpreter | ||
import org.tensorflow.lite.gpu.GpuDelegate | ||
|
||
/** | ||
* | ||
* | ||
* @author noctis | ||
* @since 1.1.0 | ||
*/ | ||
|
||
fun Aoe.Companion.createAoeClient(context: Context, modelPath: String, | ||
convertor: TensorFlowMultipleInputsOutputsInterpreter<*, *, *, *>, useGpu: Boolean): AoeClient { | ||
if (useGpu) { | ||
convertor.addDelegate(GpuDelegate()) | ||
} | ||
val client = AoeClient(context, convertor, modelPath) | ||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 40 additions & 40 deletions
80
...rflow/lite/TensorFlowLiteInterpreter.java → ...ensorflow/lite/TensorFlowInterpreter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
package com.didi.aoe.runtime.tensorflow.lite; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import com.didi.aoe.library.api.convertor.Convertor; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* 基于TensorFlow Lite的运行时Interpreter封装,用于单输入,单输出的常见场景。多路输入的场景不要继承这个类,继承 | ||
* 它的父类TensorFlowLiteMultipleInputsOutputsInterpreter,实现preProcessMulti和postProcessMulti即可。 | ||
* | ||
* @param <TInput> 范型,业务输入数据 | ||
* @param <TOutput> 范型,业务输出数据 | ||
* @param <TModelInput> 范型,模型输入数据 | ||
* @param <TModelOutput> 范型,模型输出数据 | ||
* @author noctis | ||
*/ | ||
public abstract class TensorFlowLiteInterpreter<TInput, TOutput, TModelInput, TModelOutput> extends | ||
TensorFlowLiteMultipleInputsOutputsInterpreter<TInput, TOutput, Object, TModelOutput> implements | ||
Convertor<TInput, TOutput, TModelInput, TModelOutput> { | ||
|
||
@Nullable | ||
@Override | ||
public final Object[] preProcessMulti(@NonNull TInput tInput) { | ||
Object[] inputs = new Object[1]; | ||
inputs[0] = preProcess(tInput); | ||
return inputs; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public final TOutput postProcessMulti(@Nullable Map<Integer, TModelOutput> modelOutput) { | ||
if (modelOutput != null && !modelOutput.isEmpty()) { | ||
return postProcess(modelOutput.get(0)); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
package com.didi.aoe.runtime.tensorflow.lite; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import com.didi.aoe.library.api.convertor.Convertor; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* 基于TensorFlow Lite的运行时Interpreter封装,用于单输入,单输出的常见场景。多路输入的场景不要继承这个类,继承 | ||
* 它的父类TensorFlowLiteMultipleInputsOutputsInterpreter,实现preProcessMulti和postProcessMulti即可。 | ||
* | ||
* @param <TInput> 范型,业务输入数据 | ||
* @param <TOutput> 范型,业务输出数据 | ||
* @param <TModelInput> 范型,模型输入数据 | ||
* @param <TModelOutput> 范型,模型输出数据 | ||
* @author noctis | ||
*/ | ||
public abstract class TensorFlowInterpreter<TInput, TOutput, TModelInput, TModelOutput> extends | ||
TensorFlowMultipleInputsOutputsInterpreter<TInput, TOutput, Object, TModelOutput> implements | ||
Convertor<TInput, TOutput, TModelInput, TModelOutput> { | ||
|
||
@Nullable | ||
@Override | ||
public final Object[] preProcessMulti(@NonNull TInput tInput) { | ||
Object[] inputs = new Object[1]; | ||
inputs[0] = preProcess(tInput); | ||
return inputs; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public final TOutput postProcessMulti(@Nullable Map<Integer, TModelOutput> modelOutput) { | ||
if (modelOutput != null && !modelOutput.isEmpty()) { | ||
return postProcess(modelOutput.get(0)); | ||
} | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.