RNN VAD: unit tests for RnnBasedVad
Bug: webrtc:10480 Change-Id: I4ac8ae044261f94db7a1e9559aa61f532602b408 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/195446 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32758}
This commit is contained in:

committed by
Commit Bot

parent
05266ca658
commit
e7b5c1a235
@ -30,6 +30,21 @@ namespace rnn_vad {
|
||||
namespace test {
|
||||
namespace {
|
||||
|
||||
constexpr std::array<float, kFeatureVectorSize> kFeatures = {
|
||||
-1.00131f, -0.627069f, -7.81097f, 7.86285f, -2.87145f, 3.32365f,
|
||||
-0.653161f, 0.529839f, -0.425307f, 0.25583f, 0.235094f, 0.230527f,
|
||||
-0.144687f, 0.182785f, 0.57102f, 0.125039f, 0.479482f, -0.0255439f,
|
||||
-0.0073141f, -0.147346f, -0.217106f, -0.0846906f, -8.34943f, 3.09065f,
|
||||
1.42628f, -0.85235f, -0.220207f, -0.811163f, 2.09032f, -2.01425f,
|
||||
-0.690268f, -0.925327f, -0.541354f, 0.58455f, -0.606726f, -0.0372358f,
|
||||
0.565991f, 0.435854f, 0.420812f, 0.162198f, -2.13f, 10.0089f};
|
||||
|
||||
void WarmUpRnnVad(RnnBasedVad& rnn_vad) {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
void TestFullyConnectedLayer(FullyConnectedLayer* fc,
|
||||
rtc::ArrayView<const float> input_vector,
|
||||
rtc::ArrayView<const float> expected_output) {
|
||||
@ -220,6 +235,37 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
return info.param.ToString();
|
||||
});
|
||||
|
||||
// Checks that the speech probability is zero with silence.
|
||||
TEST(RnnVadTest, CheckZeroProbabilityWithSilence) {
|
||||
RnnBasedVad rnn_vad(GetAvailableCpuFeatures());
|
||||
WarmUpRnnVad(rnn_vad);
|
||||
EXPECT_EQ(rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/true), 0.f);
|
||||
}
|
||||
|
||||
// Checks that the same output is produced after reset given the same input
|
||||
// sequence.
|
||||
TEST(RnnVadTest, CheckRnnVadReset) {
|
||||
RnnBasedVad rnn_vad(GetAvailableCpuFeatures());
|
||||
WarmUpRnnVad(rnn_vad);
|
||||
float pre = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
|
||||
rnn_vad.Reset();
|
||||
WarmUpRnnVad(rnn_vad);
|
||||
float post = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
|
||||
EXPECT_EQ(pre, post);
|
||||
}
|
||||
|
||||
// Checks that the same output is produced after silence is observed given the
|
||||
// same input sequence.
|
||||
TEST(RnnVadTest, CheckRnnVadSilence) {
|
||||
RnnBasedVad rnn_vad(GetAvailableCpuFeatures());
|
||||
WarmUpRnnVad(rnn_vad);
|
||||
float pre = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
|
||||
rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/true);
|
||||
WarmUpRnnVad(rnn_vad);
|
||||
float post = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
|
||||
EXPECT_EQ(pre, post);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace test
|
||||
} // namespace rnn_vad
|
||||
|
Reference in New Issue
Block a user