tensorflow android 喚醒詞識別

我的書:
在這裏插入圖片描述
淘寶購買鏈接
噹噹購買鏈接
京東購買鏈接

###工程源碼在
代碼我已託管到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);
        }
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章