【问题标题】:Logging and deque operation problems in Tensorflow Android Speech Recognition SampleTensorflow Android Speech Recognition Sample 中的 Logging 和 deque 操作问题
【发布时间】:2018-03-20 14:19:14
【问题描述】:

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

据我所知,

(1) SpeechActivity.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 毫秒内推断出的输出分数 (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 值是相同的。但是,这是不可能的。我的问题是我是否错过了记录信息中的某些内容,从而打印出错误的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;
  }
}

这里是平均循环过程中的日志消息两次。第一次,previousResults中的scores数组和[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对应的scores数组是[0.16993265, 0.15456167, 0.027866788, 0.107177936, 0.12646474, 0.053816866, 0.082612425, 0.059116375, 0.038425073, 0.06992877, 0.033074524, 0.07702225],但是下一次sscores数组变成了[0.14775836, 0.18298364, 0.026629224, 0.12195902, 0.111195154, 0.058891248, 0.07295453, 0.05453651, 0.04063993, 0.06559348, 0.032576166, 0.084282786]

我的第二个问题是我不知道这是怎么发生的。我的代码与RecognizeCommands.java 相同。任何线索或建议都会非常有帮助,谢谢。

【问题讨论】:

  • 抱歉,您可能想解释一下您的问题。很难理解问题是什么以及“我注意到平均结果是相同的并被最后一个结果覆盖”是什么意思
  • 非常感谢您的评论。我添加更多信息。如果有不清楚的部分,请告诉我。感谢您的宝贵时间。
  • 这是预期行为。最近的值在循环外发生变化,在循环内它们应该保持不变,你只计算平均值,你不修改值。数组的正确名称是recentResults,而不是previousResults。
  • 感谢您的回复。请问这个评论是针对问题(1)还是(2)?
  • 如果是for(1),我知道previousResults中的值在for循环中不会改变。但是,在这种情况下,每个 (currentTimeMS, currentResults) 对应该是非常不同的,currentTimeMS 应该向上计数,并且代表每个命令概率的 currentResults 应该有各种分数。因此,我的第一个问题是询问日志中显示的数字是否是计算平均值的值。如果答案是否定的,我想知道正确的日志记录代码。

标签: android tensorflow speech-recognition


【解决方案1】:

尝试更改此代码:

  // 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)));

【讨论】:

  • 非常非常非常感谢!有用!!请问这两种方法有什么区别?
猜你喜欢
  • 2013-02-03
  • 1970-01-01
  • 2016-11-16
  • 2017-06-11
  • 2020-06-12
  • 1970-01-01
  • 1970-01-01
  • 2018-07-02
相关资源
最近更新 更多