commit
86cc16d6fa
@ -0,0 +1,97 @@
|
||||
# Authors
|
||||
# * Mirco Ravanelli 2020
|
||||
# * Guillermo Cámbara 2021
|
||||
# * Sarthak Yadav 2022
|
||||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# Modified from speechbrain(https://github.com/speechbrain/speechbrain/blob/develop/speechbrain/nnet/normalization.py)
|
||||
import paddle.nn as nn
|
||||
|
||||
from paddlespeech.s2t.modules.align import BatchNorm1D
|
||||
|
||||
|
||||
class BatchNorm1d(nn.Layer):
|
||||
"""Applies 1d batch normalization to the input tensor.
|
||||
Arguments
|
||||
---------
|
||||
input_shape : tuple
|
||||
The expected shape of the input. Alternatively, use ``input_size``.
|
||||
input_size : int
|
||||
The expected size of the input. Alternatively, use ``input_shape``.
|
||||
eps : float
|
||||
This value is added to std deviation estimation to improve the numerical
|
||||
stability.
|
||||
momentum : float
|
||||
It is a value used for the running_mean and running_var computation.
|
||||
affine : bool
|
||||
When set to True, the affine parameters are learned.
|
||||
track_running_stats : bool
|
||||
When set to True, this module tracks the running mean and variance,
|
||||
and when set to False, this module does not track such statistics.
|
||||
combine_batch_time : bool
|
||||
When true, it combines batch an time axis.
|
||||
Example
|
||||
-------
|
||||
>>> input = paddle.randn([100, 10])
|
||||
>>> norm = BatchNorm1d(input_shape=input.shape)
|
||||
>>> output = norm(input)
|
||||
>>> output.shape
|
||||
Paddle.Shape([100, 10])
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
input_shape=None,
|
||||
input_size=None,
|
||||
eps=1e-05,
|
||||
momentum=0.9,
|
||||
combine_batch_time=False,
|
||||
skip_transpose=False, ):
|
||||
super().__init__()
|
||||
self.combine_batch_time = combine_batch_time
|
||||
self.skip_transpose = skip_transpose
|
||||
|
||||
if input_size is None and skip_transpose:
|
||||
input_size = input_shape[1]
|
||||
elif input_size is None:
|
||||
input_size = input_shape[-1]
|
||||
|
||||
self.norm = BatchNorm1D(input_size, momentum=momentum, epsilon=eps)
|
||||
|
||||
def forward(self, x):
|
||||
"""Returns the normalized input tensor.
|
||||
Arguments
|
||||
---------
|
||||
x : paddle.Tensor (batch, time, [channels])
|
||||
input to normalize. 2d or 3d tensors are expected in input
|
||||
4d tensors can be used when combine_dims=True.
|
||||
"""
|
||||
shape_or = x.shape
|
||||
if self.combine_batch_time:
|
||||
if x.ndim == 3:
|
||||
x = x.reshape(shape_or[0] * shape_or[1], shape_or[2])
|
||||
else:
|
||||
x = x.reshape(shape_or[0] * shape_or[1], shape_or[3],
|
||||
shape_or[2])
|
||||
|
||||
elif not self.skip_transpose:
|
||||
x = x.transpose([0, 2, 1])
|
||||
|
||||
x_n = self.norm(x)
|
||||
if self.combine_batch_time:
|
||||
x_n = x_n.reshape(shape_or)
|
||||
elif not self.skip_transpose:
|
||||
x_n = x_n.transpose([0, 2, 1])
|
||||
|
||||
return x_n
|
@ -1,27 +1,77 @@
|
||||
# u2/u2pp Streaming ASR
|
||||
# U2/U2++ Streaming ASR
|
||||
|
||||
A C++ deployment example for `PaddleSpeech/examples/wenetspeech/asr1` recipe. The model is static model from `export`, how to export model please see [here](../../../../examples/wenetspeech/asr1/). If you want using exported model, `run.sh` will download it, for the model link please see `run.sh`.
|
||||
|
||||
This example will demonstrate how to using the u2/u2++ model to recognize `wav` and compute `CER`. We using AISHELL-1 as test data.
|
||||
|
||||
## Testing with Aishell Test Data
|
||||
|
||||
### Download wav and model
|
||||
### Source `path.sh` first
|
||||
|
||||
```bash
|
||||
source path.sh
|
||||
```
|
||||
|
||||
All bins are under `echo $SPEECHX_BUILD` dir.
|
||||
|
||||
### Download dataset and model
|
||||
|
||||
```
|
||||
./run.sh --stop_stage 0
|
||||
```
|
||||
|
||||
### compute feature
|
||||
### process `cmvn` and compute feature
|
||||
|
||||
```
|
||||
```bash
|
||||
./run.sh --stage 1 --stop_stage 1
|
||||
```
|
||||
|
||||
### decoding using feature
|
||||
If you only want to convert `cmvn` file format, can using this cmd:
|
||||
|
||||
```bash
|
||||
./local/feat.sh --stage 1 --stop_stage 1
|
||||
```
|
||||
|
||||
### Decoding using `feature` input
|
||||
|
||||
```
|
||||
./run.sh --stage 2 --stop_stage 2
|
||||
```
|
||||
|
||||
### decoding using wav
|
||||
### Decoding using `wav` input
|
||||
|
||||
```
|
||||
./run.sh --stage 3 --stop_stage 3
|
||||
```
|
||||
|
||||
This stage using `u2_recognizer_main` to recognize wav file.
|
||||
|
||||
The input is `scp` file which look like this:
|
||||
```text
|
||||
# head data/split1/1/aishell_test.scp
|
||||
BAC009S0764W0121 /workspace/PaddleSpeech/speechx/examples/u2pp_ol/wenetspeech/data/test/S0764/BAC009S0764W0121.wav
|
||||
BAC009S0764W0122 /workspace/PaddleSpeech/speechx/examples/u2pp_ol/wenetspeech/data/test/S0764/BAC009S0764W0122.wav
|
||||
...
|
||||
BAC009S0764W0125 /workspace/PaddleSpeech/speechx/examples/u2pp_ol/wenetspeech/data/test/S0764/BAC009S0764W0125.wav
|
||||
```
|
||||
|
||||
If you want to recognize one wav, you can make `scp` file like this:
|
||||
```text
|
||||
key path/to/wav/file
|
||||
```
|
||||
|
||||
Then specify `--wav_rspecifier=` param for `u2_recognizer_main` bin. For other flags meaning, please see `help`:
|
||||
```bash
|
||||
u2_recognizer_main --help
|
||||
```
|
||||
|
||||
The exmaple using `u2_recgonize_main` bin please see `local/recognizer.sh`.
|
||||
|
||||
### Decoding with `wav` using quant model
|
||||
|
||||
`local/recognizer_quant.sh` is same to `local/recognizer.sh`, but using quanted model.
|
||||
|
||||
|
||||
## Results
|
||||
|
||||
Please see [here](./RESULTS.md).
|
||||
|
Loading…
Reference in new issue