MCPcopy Create free account
hub / github.com/modelscope/FunASR / encode

Method encode

funasr/models/ctc/model.py:134–160  ·  view source on GitHub ↗

Frontend + Encoder. Note that this method is used by asr_inference.py Args: speech: (Batch, Length, ...) speech_lengths: (Batch, ) ind: int

(
        self,
        speech: torch.Tensor,
        speech_lengths: torch.Tensor,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

132 return loss, stats, weight
133
134 def encode(
135 self,
136 speech: torch.Tensor,
137 speech_lengths: torch.Tensor,
138 **kwargs,
139 ) -> Tuple[torch.Tensor, torch.Tensor]:
140 """Frontend + Encoder. Note that this method is used by asr_inference.py
141 Args:
142 speech: (Batch, Length, ...)
143 speech_lengths: (Batch, )
144 ind: int
145 """
146
147 # Data augmentation
148 if self.specaug is not None and self.training:
149 speech, speech_lengths = self.specaug(speech, speech_lengths)
150
151 # Normalization for feature: e.g. Global-CMVN, Utterance-CMVN
152 if self.normalize is not None:
153 speech, speech_lengths = self.normalize(speech, speech_lengths)
154
155 # Forward encoder
156 # feats: (Batch, Length, Dim)
157 # -> encoder_out: (Batch, Length2, Dim2)
158 encoder_out, encoder_out_lens = self.encoder(speech, speech_lengths)
159
160 return encoder_out, encoder_out_lens
161
162
163 def _calc_ctc_loss(

Callers 7

forwardMethod · 0.95
inferenceMethod · 0.95
split_wordsFunction · 0.45
inferenceMethod · 0.45
forwardMethod · 0.45
inferenceMethod · 0.45
inferenceMethod · 0.45

Calls 1

normalizeMethod · 0.45

Tested by

no test coverage detected