代码之家  ›  专栏  ›  技术社区  ›  Jean Lin

Tensorflow Android语音识别示例中的日志记录和deque操作问题

  •  1
  • Jean Lin  · 技术社区  · 8 年前

    我正在学习tensorflow语音命令示例。 我在上使用的Android代码库与 tensorflow GitHub android sample 主要集中在 SpeechActivity.java RecognizeCommands.java 。除了记录消息外,我没有更改任何内容。

    据我所知,

    (1) 演讲活动。Java语言 将通过模型参考结果( outputScores )以及 currentTime recognizeCommands.processLatestResults 做后平滑。

    // 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);
    
    // Use the smoother to figure out if we've had a real recognition event.
    long currentTime = System.currentTimeMillis();
    final RecognizeCommands.RecognitionResult result =
    recognizeCommands.processLatestResults(outputScores, currentTime);
    

    (2) 在ProcessLatestResults()中, previousResults 用于存储最近500 ms内推断的输出分数( averageWindowDurationMs ==500)和 averageScores 将是我们未来想要/使用的最终分数。

    // Add the latest results to the head of the queue.
    previousResults.addLast(new Pair<Long, float[]>(currentTimeMS, currentResults));
    
    // Prune any earlier results that are too old for the averaging window.
    final long timeLimit = currentTimeMS - averageWindowDurationMs;
    while (previousResults.getFirst().first < timeLimit) {
      previousResults.removeFirst();
    }
    
    ...
    
    // Calculate the average score across all the results in the window.
    float[] averageScores = new float[labelsCount];
    for (Pair<Long, float[]> previousResult : previousResults) {
      final float[] scoresTensor = previousResult.second;
      int i = 0;
      while (i < scoresTensor.length) {
        averageScores[i] += scoresTensor[i] / howManyResults;
        ++i;
      }
    }
    

    我的问题是

    (1) 当for循环计算平均值时, previousResult.second 从每个项目读取的值相同。然而,这是不可能的。我的问题是,我是否在记录信息时遗漏了什么,以便打印出错误的 上一个结果。第二 价值或者这些分数数组是完全相同的? 以下是我的日志记录方式:

    Log.d("tmp", "start average");
    // Calculate the average score across all the results in the window.
    float[] averageScores = new float[labelsCount];
    for (Pair<Long, float[]> previousResult : previousResults) {
      final float[] scoresTensor = previousResult.second;
      Log.d("tmp", "previousResult("+previousResult.first+"): ["+Arrays.toString(previousResult.second)+"]" );
      int i = 0;
      while (i < scoresTensor.length) {
        averageScores[i] += scoresTensor[i] / howManyResults;
        ++i;
      }
    }
    

    这里是两次平均循环过程中的日志消息。第一次,分数数组 以前的结果 都是一样的 [0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225] 这是不可能的。

    start avarage
    previousResult(1520998400247): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400301): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400354): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400408): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400466): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400520): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400574): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400629): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400683): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    previousResult(1520998400737): [[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225]]
    ....
    ....
    start average
    previousResult(1520998400301): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400354): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400408): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400466): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400520): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400574): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400629): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400683): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400737): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    previousResult(1520998400791): [[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]]
    ...
    ...
    

    (2) 根据消息日志,您可以看到对应于 1520998400301 第一次是 [0.16993265、0.15456167、0.027866788、0.107177936、0.12646474、0.053816866、0.08261245、0.059116375、0.038425073、0.06992877、0.033074524、0.07702225] ,但在下一次,分数数组变为 [0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]

    我的第二个问题是,我不知道这是怎么发生的。我的代码与相同 识别命令。Java语言 。任何线索或建议都会很有帮助,谢谢。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Nikolay Shmyrev    8 年前

    尝试更改此代码:

      // Add the latest results to the head of the queue.
        previousResults.addLast(new Pair<Long, float[]>(currentTimeMS, currentResults));
    

    如下所示:

      // Add the latest results to the head of the queue.
        previousResults.addLast(new Pair<Long, float[]>(currentTimeMS, 
                                Arrays.copyOf(currentResults, currentResults.length)));