Reland "Reland "AGC2 RNN VAD: Recurrent Neural Network impl""
This reverts commit 3c9f47434f0af3b16f1b8f43cd4500be6fd2ac17.
Reason for revert: downstream projects fixed
Original change's description:
> Revert "Reland "AGC2 RNN VAD: Recurrent Neural Network impl""
>
> This reverts commit e0bba68edea74ca33f4c492eba290c089f233f6b.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Reland "AGC2 RNN VAD: Recurrent Neural Network impl"
> >
> > This reverts commit 97e349ace7a3fd64fff270f0d780e02bb708f503.
> >
> > Reason for revert: downstream projects fixed
> >
> > Original change's description:
> > > Revert "AGC2 RNN VAD: Recurrent Neural Network impl"
> > >
> > > This reverts commit 2491cb73820fe82923b848dfcab6772b4b0addb0.
> > >
> > > Reason for revert: broke internal build
> > >
> > > Original change's description:
> > > > AGC2 RNN VAD: Recurrent Neural Network impl
> > > >
> > > > RNN implementation for the AGC2 VAD that includes a fully connected
> > > > layer and a gated recurrent unit layer.
> > > >
> > > > Bug: webrtc:9076
> > > > Change-Id: Ibb8b0b4e9213f09eb9dbe118bbdc94d7e8e4f91b
> > > > Reviewed-on: https://webrtc-review.googlesource.com/72060
> > > > Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
> > > > Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> > > > Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
> > > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> > > > Cr-Commit-Position: refs/heads/master@{#23101}
> > >
> > > TBR=phoglund@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
> > >
> > > Change-Id: Ic311c4b7d79094e959d3a2c4a53c398f34c954e2
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: webrtc:9076
> > > Reviewed-on: https://webrtc-review.googlesource.com/74200
> > > Reviewed-by: Sam Zackrisson <saza@webrtc.org>
> > > Commit-Queue: Sam Zackrisson <saza@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#23103}
> >
> > TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
> >
> > Change-Id: I0c7f8e0f59be926322d05b1da1d4d19c0777dab2
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Bug: webrtc:9076
> > Reviewed-on: https://webrtc-review.googlesource.com/74460
> > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
> > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#23113}
>
> TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
>
> Change-Id: I3985a6d38df1d4438a50d031bc9f6cf41eb83121
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:9076
> Reviewed-on: https://webrtc-review.googlesource.com/74560
> Reviewed-by: Sam Zackrisson <saza@webrtc.org>
> Commit-Queue: Sam Zackrisson <saza@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23117}
TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: webrtc:9076
Change-Id: I4d81786837017d4daf0dbb1218306795b977ade5
Reviewed-on: https://webrtc-review.googlesource.com/74760
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23138}
2018-05-07 09:29:54 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_RNN_H_
|
|
|
|
|
#define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_RNN_H_
|
|
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <sys/types.h>
|
Reland "Reland "AGC2 RNN VAD: Recurrent Neural Network impl""
This reverts commit 3c9f47434f0af3b16f1b8f43cd4500be6fd2ac17.
Reason for revert: downstream projects fixed
Original change's description:
> Revert "Reland "AGC2 RNN VAD: Recurrent Neural Network impl""
>
> This reverts commit e0bba68edea74ca33f4c492eba290c089f233f6b.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Reland "AGC2 RNN VAD: Recurrent Neural Network impl"
> >
> > This reverts commit 97e349ace7a3fd64fff270f0d780e02bb708f503.
> >
> > Reason for revert: downstream projects fixed
> >
> > Original change's description:
> > > Revert "AGC2 RNN VAD: Recurrent Neural Network impl"
> > >
> > > This reverts commit 2491cb73820fe82923b848dfcab6772b4b0addb0.
> > >
> > > Reason for revert: broke internal build
> > >
> > > Original change's description:
> > > > AGC2 RNN VAD: Recurrent Neural Network impl
> > > >
> > > > RNN implementation for the AGC2 VAD that includes a fully connected
> > > > layer and a gated recurrent unit layer.
> > > >
> > > > Bug: webrtc:9076
> > > > Change-Id: Ibb8b0b4e9213f09eb9dbe118bbdc94d7e8e4f91b
> > > > Reviewed-on: https://webrtc-review.googlesource.com/72060
> > > > Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
> > > > Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> > > > Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
> > > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> > > > Cr-Commit-Position: refs/heads/master@{#23101}
> > >
> > > TBR=phoglund@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
> > >
> > > Change-Id: Ic311c4b7d79094e959d3a2c4a53c398f34c954e2
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: webrtc:9076
> > > Reviewed-on: https://webrtc-review.googlesource.com/74200
> > > Reviewed-by: Sam Zackrisson <saza@webrtc.org>
> > > Commit-Queue: Sam Zackrisson <saza@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#23103}
> >
> > TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
> >
> > Change-Id: I0c7f8e0f59be926322d05b1da1d4d19c0777dab2
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Bug: webrtc:9076
> > Reviewed-on: https://webrtc-review.googlesource.com/74460
> > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
> > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#23113}
>
> TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
>
> Change-Id: I3985a6d38df1d4438a50d031bc9f6cf41eb83121
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:9076
> Reviewed-on: https://webrtc-review.googlesource.com/74560
> Reviewed-by: Sam Zackrisson <saza@webrtc.org>
> Commit-Queue: Sam Zackrisson <saza@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23117}
TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: webrtc:9076
Change-Id: I4d81786837017d4daf0dbb1218306795b977ade5
Reviewed-on: https://webrtc-review.googlesource.com/74760
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23138}
2018-05-07 09:29:54 +00:00
|
|
|
#include <array>
|
|
|
|
|
|
|
|
|
|
#include "api/array_view.h"
|
|
|
|
|
#include "modules/audio_processing/agc2/rnn_vad/common.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace rnn_vad {
|
|
|
|
|
|
|
|
|
|
// Maximum number of units for a fully-connected layer. This value is used to
|
|
|
|
|
// over-allocate space for fully-connected layers output vectors (implemented as
|
|
|
|
|
// std::array). The value should equal the number of units of the largest
|
|
|
|
|
// fully-connected layer.
|
|
|
|
|
constexpr size_t kFullyConnectedLayersMaxUnits = 24;
|
|
|
|
|
|
|
|
|
|
// Maximum number of units for a recurrent layer. This value is used to
|
|
|
|
|
// over-allocate space for recurrent layers state vectors (implemented as
|
|
|
|
|
// std::array). The value should equal the number of units of the largest
|
|
|
|
|
// recurrent layer.
|
|
|
|
|
constexpr size_t kRecurrentLayersMaxUnits = 24;
|
|
|
|
|
|
|
|
|
|
// Fully-connected layer.
|
|
|
|
|
class FullyConnectedLayer {
|
|
|
|
|
public:
|
|
|
|
|
FullyConnectedLayer(const size_t input_size,
|
|
|
|
|
const size_t output_size,
|
|
|
|
|
const rtc::ArrayView<const int8_t> bias,
|
|
|
|
|
const rtc::ArrayView<const int8_t> weights,
|
|
|
|
|
float (*const activation_function)(float));
|
|
|
|
|
FullyConnectedLayer(const FullyConnectedLayer&) = delete;
|
|
|
|
|
FullyConnectedLayer& operator=(const FullyConnectedLayer&) = delete;
|
|
|
|
|
~FullyConnectedLayer();
|
|
|
|
|
size_t input_size() const { return input_size_; }
|
|
|
|
|
size_t output_size() const { return output_size_; }
|
|
|
|
|
rtc::ArrayView<const float> GetOutput() const;
|
|
|
|
|
// Computes the fully-connected layer output.
|
|
|
|
|
void ComputeOutput(rtc::ArrayView<const float> input);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const size_t input_size_;
|
|
|
|
|
const size_t output_size_;
|
|
|
|
|
const rtc::ArrayView<const int8_t> bias_;
|
|
|
|
|
const rtc::ArrayView<const int8_t> weights_;
|
|
|
|
|
float (*const activation_function_)(float);
|
|
|
|
|
// The output vector of a recurrent layer has length equal to |output_size_|.
|
|
|
|
|
// However, for efficiency, over-allocation is used.
|
|
|
|
|
std::array<float, kFullyConnectedLayersMaxUnits> output_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Recurrent layer with gated recurrent units (GRUs).
|
|
|
|
|
class GatedRecurrentLayer {
|
|
|
|
|
public:
|
|
|
|
|
GatedRecurrentLayer(const size_t input_size,
|
|
|
|
|
const size_t output_size,
|
|
|
|
|
const rtc::ArrayView<const int8_t> bias,
|
|
|
|
|
const rtc::ArrayView<const int8_t> weights,
|
|
|
|
|
const rtc::ArrayView<const int8_t> recurrent_weights,
|
|
|
|
|
float (*const activation_function)(float));
|
|
|
|
|
GatedRecurrentLayer(const GatedRecurrentLayer&) = delete;
|
|
|
|
|
GatedRecurrentLayer& operator=(const GatedRecurrentLayer&) = delete;
|
|
|
|
|
~GatedRecurrentLayer();
|
|
|
|
|
size_t input_size() const { return input_size_; }
|
|
|
|
|
size_t output_size() const { return output_size_; }
|
|
|
|
|
rtc::ArrayView<const float> GetOutput() const;
|
|
|
|
|
void Reset();
|
|
|
|
|
// Computes the recurrent layer output and updates the status.
|
|
|
|
|
void ComputeOutput(rtc::ArrayView<const float> input);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const size_t input_size_;
|
|
|
|
|
const size_t output_size_;
|
|
|
|
|
const rtc::ArrayView<const int8_t> bias_;
|
|
|
|
|
const rtc::ArrayView<const int8_t> weights_;
|
|
|
|
|
const rtc::ArrayView<const int8_t> recurrent_weights_;
|
|
|
|
|
float (*const activation_function_)(float);
|
|
|
|
|
// The state vector of a recurrent layer has length equal to |output_size_|.
|
|
|
|
|
// However, to avoid dynamic allocation, over-allocation is used.
|
|
|
|
|
std::array<float, kRecurrentLayersMaxUnits> state_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Recurrent network based VAD.
|
|
|
|
|
class RnnBasedVad {
|
|
|
|
|
public:
|
|
|
|
|
RnnBasedVad();
|
|
|
|
|
RnnBasedVad(const RnnBasedVad&) = delete;
|
|
|
|
|
RnnBasedVad& operator=(const RnnBasedVad&) = delete;
|
|
|
|
|
~RnnBasedVad();
|
|
|
|
|
void Reset();
|
|
|
|
|
// Compute and returns the probability of voice (range: [0.0, 1.0]).
|
2018-05-15 15:52:38 +02:00
|
|
|
float ComputeVadProbability(
|
|
|
|
|
rtc::ArrayView<const float, kFeatureVectorSize> feature_vector,
|
|
|
|
|
bool is_silence);
|
Reland "Reland "AGC2 RNN VAD: Recurrent Neural Network impl""
This reverts commit 3c9f47434f0af3b16f1b8f43cd4500be6fd2ac17.
Reason for revert: downstream projects fixed
Original change's description:
> Revert "Reland "AGC2 RNN VAD: Recurrent Neural Network impl""
>
> This reverts commit e0bba68edea74ca33f4c492eba290c089f233f6b.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Reland "AGC2 RNN VAD: Recurrent Neural Network impl"
> >
> > This reverts commit 97e349ace7a3fd64fff270f0d780e02bb708f503.
> >
> > Reason for revert: downstream projects fixed
> >
> > Original change's description:
> > > Revert "AGC2 RNN VAD: Recurrent Neural Network impl"
> > >
> > > This reverts commit 2491cb73820fe82923b848dfcab6772b4b0addb0.
> > >
> > > Reason for revert: broke internal build
> > >
> > > Original change's description:
> > > > AGC2 RNN VAD: Recurrent Neural Network impl
> > > >
> > > > RNN implementation for the AGC2 VAD that includes a fully connected
> > > > layer and a gated recurrent unit layer.
> > > >
> > > > Bug: webrtc:9076
> > > > Change-Id: Ibb8b0b4e9213f09eb9dbe118bbdc94d7e8e4f91b
> > > > Reviewed-on: https://webrtc-review.googlesource.com/72060
> > > > Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
> > > > Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> > > > Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
> > > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> > > > Cr-Commit-Position: refs/heads/master@{#23101}
> > >
> > > TBR=phoglund@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
> > >
> > > Change-Id: Ic311c4b7d79094e959d3a2c4a53c398f34c954e2
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: webrtc:9076
> > > Reviewed-on: https://webrtc-review.googlesource.com/74200
> > > Reviewed-by: Sam Zackrisson <saza@webrtc.org>
> > > Commit-Queue: Sam Zackrisson <saza@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#23103}
> >
> > TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
> >
> > Change-Id: I0c7f8e0f59be926322d05b1da1d4d19c0777dab2
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Bug: webrtc:9076
> > Reviewed-on: https://webrtc-review.googlesource.com/74460
> > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
> > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#23113}
>
> TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
>
> Change-Id: I3985a6d38df1d4438a50d031bc9f6cf41eb83121
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:9076
> Reviewed-on: https://webrtc-review.googlesource.com/74560
> Reviewed-by: Sam Zackrisson <saza@webrtc.org>
> Commit-Queue: Sam Zackrisson <saza@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23117}
TBR=phoglund@webrtc.org,saza@webrtc.org,alessiob@webrtc.org,aleloi@webrtc.org,ivoc@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: webrtc:9076
Change-Id: I4d81786837017d4daf0dbb1218306795b977ade5
Reviewed-on: https://webrtc-review.googlesource.com/74760
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23138}
2018-05-07 09:29:54 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FullyConnectedLayer input_layer_;
|
|
|
|
|
GatedRecurrentLayer hidden_layer_;
|
|
|
|
|
FullyConnectedLayer output_layer_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rnn_vad
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_RNN_H_
|