tensorflow android 关键词 激活

来源:互联网 发布:淘宝上怎么添加旺旺 编辑:程序博客网 时间:2024/05/22 17:04

工程源码在

代码我已托管到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;    // Load the TensorFlow model.    inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILENAME);      // Run the model.      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);        }    }
原创粉丝点击