MCPcopy Create free account
hub / github.com/NVIDIA/DALI / test_decoded_vs_generated

Function test_decoded_vs_generated

dali/test/python/reader/test_nemo_asr.py:204–283  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202
203
204def test_decoded_vs_generated():
205 batch_size = 3
206 pipeline = NemoAsrReaderPipeline(batch_size=batch_size)
207
208 for iter in range(1):
209 out = pipeline.run()
210 for idx in range(batch_size):
211 audio_plain_i = out[0].at(idx)
212 audio_plain_f = out[1].at(idx)
213 audio_downmix_i = out[2].at(idx)
214 audio_downmix_f = out[3].at(idx)
215 audio_resampled1_i = out[4].at(idx)
216 audio_resampled1_f = out[5].at(idx)
217 audio_resampled2_i = out[6].at(idx)
218 audio_resampled2_f = out[7].at(idx)
219 text = out[8].at(idx)
220 text_non_ascii = out[9].at(idx)
221
222 ref_plain_i = ref_i[idx]
223 np.testing.assert_allclose(audio_plain_i, ref_plain_i, rtol=1e-7)
224
225 ref_plain_f = ref_i[idx].astype(np.float32) / 32767
226 np.testing.assert_allclose(audio_plain_f, ref_plain_f, rtol=1e-4)
227
228 ref_downmix_i_float = ref_i[idx].astype(np.float32).mean(axis=1, keepdims=1)
229
230 ref_downmix_i = ref_downmix_i_float.astype(np.int16).flatten()
231 np.testing.assert_allclose(audio_downmix_i, ref_downmix_i, atol=1)
232
233 ref_downmix_f = (ref_downmix_i_float / 32767).flatten()
234 np.testing.assert_allclose(audio_downmix_f, ref_downmix_f, rtol=1e-4)
235
236 ref_resampled1_float = generate_waveforms(
237 lengths[idx] * rate1 / rates[idx], freqs[idx] * (rates[idx] / rate1)
238 )
239 ref_resampled1_downmix = ref_resampled1_float.astype(np.float32).mean(
240 axis=1, keepdims=1
241 )
242 ref_resampled1_i = (ref_resampled1_downmix * 32767).astype(np.int16).flatten()
243 # resampling - allow for 1e-3 dynamic range error
244 np.testing.assert_allclose(
245 audio_resampled1_i, ref_resampled1_i, atol=round(32767 * 1e-3)
246 )
247
248 ref_resampled1_f = ref_resampled1_downmix.flatten()
249 # resampling - allow for 1e-3 dynamic range error
250 np.testing.assert_allclose(audio_resampled1_f, ref_resampled1_f, atol=1e-3)
251
252 ref_resampled2_float = generate_waveforms(
253 lengths[idx] * rate2 / rates[idx], freqs[idx] * (rates[idx] / rate2)
254 )
255 ref_resampled2_downmix = ref_resampled2_float.astype(np.float32).mean(
256 axis=1, keepdims=1
257 )
258 ref_resampled2_i = (ref_resampled2_downmix * 32767).astype(np.int16).flatten()
259 # resampling - allow for 1e-3 dynamic range error
260 np.testing.assert_allclose(
261 audio_resampled2_i, ref_resampled2_i, atol=round(32767 * 1e-3)

Callers

nothing calls this directly

Calls 5

generate_waveformsFunction · 0.90
roundFunction · 0.85
runMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected