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

Function check_audio_decoder_correctness

dali/test/python/decoder/test_audio.py:179–212  ·  view source on GitHub ↗
(fmt, dtype)

Source from the content-addressed store, hash-verified

177
178
179def check_audio_decoder_correctness(fmt, dtype):
180 batch_size = 16
181 niterations = 10
182
183 @pipeline_def(batch_size=batch_size, device_id=0, num_threads=4)
184 def audio_decoder_pipe(fnames, dtype, downmix=False):
185 encoded, _ = fn.readers.file(files=fnames)
186 decoded, _ = fn.decoders.audio(encoded, dtype=dtype, downmix=downmix)
187 return decoded
188
189 audio_files = get_files(os.path.join("db", "audio", fmt), fmt)
190 npy_files = [os.path.splitext(fpath)[0] + ".npy" for fpath in audio_files]
191 pipe = audio_decoder_pipe(audio_files, dtype)
192 for it in range(niterations):
193 data = pipe.run()
194 for s in range(batch_size):
195 sample_idx = (it * batch_size + s) % len(audio_files)
196 ref = np.load(npy_files[sample_idx])
197 if len(ref.shape) == 1:
198 ref = np.expand_dims(ref, 1)
199 arr = np.array(data[0][s])
200 assert arr.shape == ref.shape
201 if fmt == "ogg":
202 # For OGG Vorbis, we consider errors any value that is off by more than 1
203 # TODO(janton): There is a bug in libsndfile that produces underflow/overflow.
204 # Remove this when the bug is fixed.
205 # Tuple with two arrays, we just need the first dimension
206 wrong_values = np.where(np.abs(arr - ref) > 1)[0]
207 nerrors = len(wrong_values)
208 assert nerrors <= 1
209 # TODO(janton): Uncomment this when the bug is fixed
210 # np.testing.assert_allclose(arr, ref, atol=1)
211 else:
212 np.testing.assert_equal(arr, ref)
213
214
215def test_audio_decoder_correctness():

Callers

nothing calls this directly

Calls 4

get_filesFunction · 0.90
audio_decoder_pipeFunction · 0.70
runMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected