-
-
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
132 changed files
with
2,686 additions
and
1,943 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
flutter/flutter_aoe_plugin/README.md → flutter/aoe_flutter_plugin/README.md
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,6 +1,6 @@ | ||
# flutter_aoe_plugin | ||
# aoeflutter | ||
|
||
A new Flutter plugin. | ||
Flutter plugin for AoE. | ||
|
||
## Getting Started | ||
|
||
|
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
...lutter_plugin/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.flutter.plugins; | ||
|
||
import io.flutter.plugin.common.PluginRegistry; | ||
import com.didi.aoe.aoeflutter.AoeFlutterPlugin; | ||
|
||
/** | ||
* Generated file. Do not edit. | ||
*/ | ||
public final class GeneratedPluginRegistrant { | ||
public static void registerWith(PluginRegistry registry) { | ||
if (alreadyRegisteredWith(registry)) { | ||
return; | ||
} | ||
AoeFlutterPlugin.registerWith(registry.registrarFor("com.didi.aoe.aoeflutter.AoeFlutterPlugin")); | ||
} | ||
|
||
private static boolean alreadyRegisteredWith(PluginRegistry registry) { | ||
final String key = GeneratedPluginRegistrant.class.getCanonicalName(); | ||
if (registry.hasPlugin(key)) { | ||
return true; | ||
} | ||
registry.registrarFor(key); | ||
return false; | ||
} | ||
} |
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
File renamed without changes.
Binary file not shown.
3 changes: 2 additions & 1 deletion
3
.../gradle/wrapper/gradle-wrapper.properties → .../gradle/wrapper/gradle-wrapper.properties
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,5 +1,6 @@ | ||
#Mon Mar 16 00:06:01 CST 2020 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip |
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 @@ | ||
rootProject.name = 'aoeflutter' |
2 changes: 1 addition & 1 deletion
2
...ugin/android/src/main/AndroidManifest.xml → ...ugin/android/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.didi.aoe.flutter_aoe_plugin"> | ||
package="com.didi.aoe.aoeflutter"> | ||
</manifest> |
105 changes: 105 additions & 0 deletions
105
...er/aoe_flutter_plugin/android/src/main/kotlin/com/didi/aoe/aoeflutter/AoeFlutterPlugin.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,105 @@ | ||
package com.didi.aoe.aoeflutter | ||
|
||
import android.content.Context | ||
import com.didi.aoe.aoeflutter.model.model.InterceptorError | ||
import com.didi.aoe.aoeflutter.model.model.ModelOutput | ||
import com.didi.aoe.aoeflutter.model.model.PerformanceInfo | ||
import com.didi.aoe.library.core.AoeClient | ||
import com.didi.aoe.library.logging.LoggerFactory | ||
import com.example.aoe_flutter.interpreter.MnistTensorFlowLiteInterpreter | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
import io.flutter.plugin.common.MethodChannel.Result | ||
import io.flutter.plugin.common.PluginRegistry.Registrar | ||
|
||
/** AoeFlutterPlugin */ | ||
class AoeFlutterPlugin(private val mContext: Context) : FlutterPlugin, MethodCallHandler { | ||
private val mLogger = LoggerFactory.getLogger("AoeFlutterPlugin") | ||
private var mAoeClient: AoeClient? = null | ||
|
||
private val mPerf = PerformanceInfo() | ||
|
||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | ||
val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "aoeflutter") | ||
channel.setMethodCallHandler(AoeFlutterPlugin(flutterPluginBinding.applicationContext)); | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun registerWith(registrar: Registrar) { | ||
val channel = MethodChannel(registrar.messenger(), "aoeflutter") | ||
channel.setMethodCallHandler(AoeFlutterPlugin(registrar.context())) | ||
} | ||
} | ||
|
||
override fun onMethodCall(call: MethodCall, result: Result) { | ||
if ("start" == call.method) { | ||
start(call, result) | ||
} else if ("process" == call.method) { | ||
process(call, result) | ||
} else if ("stop" == call.method) { | ||
stop(call, result) | ||
} else { | ||
result.notImplemented() | ||
} | ||
} | ||
|
||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
|
||
} | ||
|
||
private fun start(call: MethodCall, result: MethodChannel.Result) { | ||
val inputs = call.arguments as Map<*, *> | ||
val runtime = inputs["runtime"] | ||
val modelDir = inputs["modelDir"] as String | ||
mLogger.debug("runtime: $runtime, modelDir: $modelDir") | ||
if (inputs.isEmpty()) { | ||
result.error("", InterceptorError.parameterError.errMsg, InterceptorError.parameterError.toMap()) | ||
return | ||
} | ||
// Fixme 临时处理 | ||
val aoeClient = AoeClient(mContext, | ||
AoeClient.Options() | ||
.setInterpreter(MnistTensorFlowLiteInterpreter::class.java), | ||
modelDir) | ||
mAoeClient = aoeClient | ||
mAoeClient?.init(object : AoeClient.OnInitListener() { | ||
override fun onSuccess() { | ||
super.onSuccess() | ||
mLogger.debug("init Success") | ||
result.success(ModelOutput(data = true).toMap()) | ||
} | ||
|
||
override fun onFailed(code: Int, msg: String?) { | ||
super.onFailed(code, msg) | ||
mLogger.debug("init Failed $code $msg") | ||
result.error(code.toString(), msg, | ||
ModelOutput(error = InterceptorError.modelError).toMap()) | ||
} | ||
}) | ||
|
||
} | ||
|
||
private fun process(call: MethodCall, result: MethodChannel.Result) { | ||
|
||
val input = call.argument<Any>("data") | ||
val output = mAoeClient?.process(input) | ||
val statInfo = mAoeClient?.acquireLatestStatInfo() | ||
|
||
if (statInfo != null) { | ||
mPerf.time.tracks(statInfo.timeCostInMills.toFloat()) | ||
mPerf.cpu.tracks(statInfo.cpuRate) | ||
mPerf.mem.tracks(statInfo.memoryInfo) | ||
} | ||
val out = ModelOutput(data = output, performance = mPerf) | ||
mLogger.debug("process $out") | ||
result.success(out.toMap()) | ||
} | ||
|
||
private fun stop(call: MethodCall, result: MethodChannel.Result) { | ||
mAoeClient?.release() | ||
result.success(ModelOutput(data = true).toMap()) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...c/main/kotlin/com/didi/aoe/aoeflutter/model/interpreter/MnistTensorFlowLiteInterpreter.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,49 @@ | ||
package com.example.aoe_flutter.interpreter | ||
|
||
import com.didi.aoe.runtime.tensorflow.lite.TensorFlowInterpreter | ||
import java.nio.ByteBuffer | ||
import android.util.Log | ||
import kotlin.math.roundToInt | ||
|
||
/** | ||
* | ||
* | ||
* @author noctis | ||
* @since 1.1.0 | ||
*/ | ||
class MnistTensorFlowLiteInterpreter : TensorFlowInterpreter<ByteArray, List<Int>?, FloatArray, Array<FloatArray>>() { | ||
private val TAG = "MnistInterpreter" | ||
override fun postProcess(modelOutput: Array<FloatArray>?): List<Int>? { | ||
|
||
if (modelOutput != null && modelOutput.size == 1) { | ||
val result = modelOutput[0].map {it.roundToInt()} | ||
Log.d(TAG, "postProcess ${result.toTypedArray().contentToString()}") | ||
return result | ||
//return modelOutput[0].indexOf(modelOutput[0].max()!!) | ||
// | ||
// | ||
//for (i in modelOutput[0].indices) { | ||
// if (modelOutput[0][i].compareTo(1f) == 0) { | ||
// return i | ||
// } | ||
//} | ||
} | ||
|
||
return null | ||
} | ||
|
||
override fun preProcess(input: ByteArray?): FloatArray? { | ||
//Log.d(TAG, "preProcess ${input?.contentToString()} ${input?.size}") | ||
if (input == null) { | ||
return null | ||
} | ||
val r = FloatArray(input.size / 4) | ||
for (i in input.indices step 4) { | ||
r[i / 4] = Float.fromBits(input[i].toInt() or | ||
input[i + 1].toInt() shl 8 or | ||
input[i + 2].toInt() shl 16 or | ||
input[i + 3].toInt() shl 24) | ||
} | ||
return r | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
..._flutter_plugin/android/src/main/kotlin/com/didi/aoe/aoeflutter/model/model/DeviceInfo.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,33 @@ | ||
package com.didi.aoe.aoeflutter.model.model | ||
|
||
/** | ||
* | ||
* | ||
* @author noctis | ||
* @since 1.1.0 | ||
*/ | ||
data class DeviceInfo @JvmOverloads constructor( | ||
var uuid: String = "", | ||
var name: String = "", | ||
var model: String = "", | ||
var system: String = "", | ||
var version: String = "", | ||
var disk: String = "", | ||
var memory: String = "", | ||
var ip: String = "", | ||
var macAddress: String = "" | ||
) { | ||
fun toMap(): Map<String, Any?> { | ||
return mapOf( | ||
Pair("uuid", uuid), | ||
Pair("name", name), | ||
Pair("model", model), | ||
Pair("system", system), | ||
Pair("version", version), | ||
Pair("disk", disk), | ||
Pair("memory", memory), | ||
Pair("ip", ip), | ||
Pair("macAddress", macAddress) | ||
) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...er_plugin/android/src/main/kotlin/com/didi/aoe/aoeflutter/model/model/InterceptorError.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,46 @@ | ||
package com.didi.aoe.aoeflutter.model.model | ||
|
||
/** | ||
* | ||
* | ||
* @author noctis | ||
* @since 1.1.0 | ||
*/ | ||
enum class InterceptorErrorType { | ||
InValidParameter, //参数异常 | ||
InValidInterceptorError, //推理框架无效 | ||
InValidModelError, //模型无效 | ||
InValidSampleError, //测试数据集无效 | ||
ProcessError, //推理异常 | ||
} | ||
|
||
data class InterceptorError @JvmOverloads constructor( | ||
var errType: InterceptorErrorType = InterceptorErrorType.InValidParameter, | ||
var errMsg: String = "" | ||
|
||
) { | ||
fun toMap(): Map<String, Any?> { | ||
return mapOf( | ||
Pair("errType", errType), | ||
Pair("errMsg", errMsg) | ||
) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
val parameterError = | ||
InterceptorError(InterceptorErrorType.InValidParameter, "the parameters is invalid") | ||
|
||
@JvmStatic | ||
val interceptorError = InterceptorError(InterceptorErrorType.InValidInterceptorError, | ||
"can not suppport the infer inframework or can not load the model") | ||
|
||
@JvmStatic | ||
val modelError = InterceptorError(InterceptorErrorType.InValidModelError, | ||
"model does not exist") | ||
|
||
@JvmStatic | ||
val sampleError = InterceptorError(InterceptorErrorType.InValidSampleError, | ||
"sample data invalid") | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...flutter_plugin/android/src/main/kotlin/com/didi/aoe/aoeflutter/model/model/ModelOutput.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,23 @@ | ||
package com.didi.aoe.aoeflutter.model.model | ||
|
||
/** | ||
* | ||
* | ||
* @author noctis | ||
* @since 1.1.0 | ||
*/ | ||
data class ModelOutput @JvmOverloads constructor( | ||
var data: Any? = null, | ||
var error: InterceptorError? = null, | ||
var performance: PerformanceInfo? = null) { | ||
|
||
fun toMap(): Map<String, Any?> { | ||
return mapOf( | ||
Pair("data", if (data != null) data else Any()), | ||
Pair("error", if (error != null) error?.toMap() else emptyMap()), | ||
Pair("performance", if (performance != null) performance?.toMap() else emptyMap()) | ||
) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.