作者:沉沉浮浮触涙水 | 来源:互联网 | 2023-05-16 02:07
工程源码在代码我已托管到github上了。里面有一个已经编译好的apk,adbinstall后就可以实际使用了。https:github.comshichaogtensor
工程源码在
代码我已托管到github上了。里面有一个已经编译好的apk,
adb install 后就可以实际使用了。
https://github.com/shichaog/tensorflow-android-speech-kws
基于官网。
Android tensorflow API
private static final String LABEL_FILENAME = "file:///android_asset/conv_actions_house_labels.txt";
private static final String MODEL_FILENAME = "file:///android_asset/my_house_frozen_graph.pb";
private TensorFlowInferenceInterface inferenceInterface;
inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILENAME);
inferenceInterface.feed(SAMPLE_RATE_NAME, sampleRateList);
inferenceInterface.feed(INPUT_DATA_NAME, floatInputBuffer, RECORDING_LENGTH, 1);
inferenceInterface.run(outputScoresNames);
inferenceInterface.fetch(OUTPUT_SCORES_NAME, outputScores);
以上就是android 的API,和python的流程基本一直。
创建这个流程图就是在创建计算图,并且加载模型参数。
public TensorFlowInferenceInterface(AssetManager var1, String var2) {
this.prepareNativeRuntime();
this.modelName = var2;
this.g = new Graph();
this.sess = new Session(this.g);
this.runner = this.sess.runner();
boolean var3 = var2.startsWith("file:///android_asset/");
Object var4 = null;
try {
String var5 = var3?var2.split("file:///android_asset/")[1]:var2;
var4 = var1.open(var5);
} catch (IOException var9) {
if(var3) {
throw new RuntimeException("Failed to load model from \'" + var2 + "\'", var9);
}
try {
var4 = new FileInputStream(var2);
} catch (IOException var8) {
throw new RuntimeException("Failed to load model from \'" + var2 + "\'", var9);
}
}
try {
this.loadGraph((InputStream)var4, this.g);
((InputStream)var4).close();
Log.i("TensorFlowInferenceInterface", "Successfully loaded model from \'" + var2 + "\'");
} catch (IOException var7) {
throw new RuntimeException("Failed to load model from \'" + var2 + "\'", var7);
}
}