From a8359fd0409751832d964d204857c679e831a35d Mon Sep 17 00:00:00 2001 From: Joaquin Anton Date: Thu, 25 Aug 2022 14:33:56 +0200 Subject: [PATCH 1/5] Deprecate in favor of Signed-off-by: Joaquin Anton --- dali/operators/audio/resample.cc | 17 ++++++++++++++++- dali/operators/audio/resample_gpu.cc | 4 ++++ .../test/python/operator/test_audio_resample.py | 8 ++++---- dali/test/python/test_dali_cpu_only.py | 4 ++-- .../python/test_dali_variable_batch_size.py | 4 ++-- dali/test/python/test_eager_coverage.py | 4 ++-- dali/test/python/test_torch_pipeline_rnnt.py | 2 +- 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/dali/operators/audio/resample.cc b/dali/operators/audio/resample.cc index 14d8a4c911..4464dbf41e 100644 --- a/dali/operators/audio/resample.cc +++ b/dali/operators/audio/resample.cc @@ -22,7 +22,7 @@ namespace dali { -DALI_SCHEMA(experimental__AudioResample) +DALI_SCHEMA(AudioResample) .DocStr(R"(Resamples an audio signal. The resampling is achieved by applying a sinc filter with Hann window with an extent @@ -96,6 +96,17 @@ type. Example:: )", nullptr, false); +// Deprecated alias +DALI_SCHEMA(experimental__AudioResample) + .AddParent("AudioResample") + .NumInput(1) + .NumOutput(1) + .Deprecate( + "AudioResample", + R"code(This is just an deprecated alias kept for backward compatibility.)code"); // Deprecated + // in 1.18 + + namespace audio { using kernels::InTensorCPU; @@ -185,6 +196,10 @@ class ResampleCPU : public ResampleBase { } // namespace audio + +// Kept for backwards compatibility DALI_REGISTER_OPERATOR(experimental__AudioResample, audio::ResampleCPU, CPU); +DALI_REGISTER_OPERATOR(AudioResample, audio::ResampleCPU, CPU); + } // namespace dali diff --git a/dali/operators/audio/resample_gpu.cc b/dali/operators/audio/resample_gpu.cc index bf1fb82d80..e507c2e03b 100644 --- a/dali/operators/audio/resample_gpu.cc +++ b/dali/operators/audio/resample_gpu.cc @@ -74,6 +74,10 @@ class ResampleGPU : public ResampleBase { } // namespace audio + +// Kept for backwards compatibility DALI_REGISTER_OPERATOR(experimental__AudioResample, audio::ResampleGPU, GPU); +DALI_REGISTER_OPERATOR(AudioResample, audio::ResampleGPU, GPU); + } // namespace dali diff --git a/dali/test/python/operator/test_audio_resample.py b/dali/test/python/operator/test_audio_resample.py index 0646ce97d3..eda89fa548 100644 --- a/dali/test/python/operator/test_audio_resample.py +++ b/dali/test/python/operator/test_audio_resample.py @@ -52,9 +52,9 @@ def audio_decoder_pipe(device): audio1, sr1 = fn.decoders.audio(encoded, dtype=types.FLOAT, sample_rate=out_sr) if device == 'gpu': audio0 = audio0.gpu() - audio2 = fn.experimental.audio_resample(audio0, in_rate=sr0, out_rate=out_sr) - audio3 = fn.experimental.audio_resample(audio0, scale=out_sr / sr0) - audio4 = fn.experimental.audio_resample(audio0, out_length=fn.shapes(audio1)[0]) + audio2 = fn.audio_resample(audio0, in_rate=sr0, out_rate=out_sr) + audio3 = fn.audio_resample(audio0, scale=out_sr / sr0) + audio4 = fn.audio_resample(audio0, out_length=fn.shapes(audio1)[0]) return audio1, audio2, audio3, audio4 @@ -87,7 +87,7 @@ def _test_type_conversion(device, src_type, in_values, dst_type, out_values, eps @pipeline_def(batch_size=len(in_values)) def test_pipe(device): input = fn.external_source(in_data, batch=False, cycle='quiet', device=device) - return fn.experimental.audio_resample(input, dtype=dst_type, scale=1, quality=0) + return fn.audio_resample(input, dtype=dst_type, scale=1, quality=0) pipe = test_pipe(device, device_id=0, num_threads=4) pipe.build() diff --git a/dali/test/python/test_dali_cpu_only.py b/dali/test/python/test_dali_cpu_only.py index 42a47fe370..5dbcb869ea 100644 --- a/dali/test/python/test_dali_cpu_only.py +++ b/dali/test/python/test_dali_cpu_only.py @@ -451,7 +451,7 @@ def test_to_decibels_cpu(): def test_audio_resample(): - check_single_input(fn.experimental.audio_resample, get_data=get_audio_data, input_layout=None, + check_single_input(fn.audio_resample, get_data=get_audio_data, input_layout=None, scale=1.25) @@ -1231,7 +1231,7 @@ def file_properties(files): "math.min", "numba.fn.experimental.numba_function", "dl_tensor_python_function", - "experimental.audio_resample", + "audio_resample", ] excluded_methods = [ diff --git a/dali/test/python/test_dali_variable_batch_size.py b/dali/test/python/test_dali_variable_batch_size.py index 24dc4d6ce6..11ea183e55 100644 --- a/dali/test/python/test_dali_variable_batch_size.py +++ b/dali/test/python/test_dali_variable_batch_size.py @@ -346,7 +346,7 @@ def test_ops_image_custom_args(): (fn.preemphasis_filter, {}), (fn.spectrogram, {'nfft': 60, 'window_length': 50, 'window_step': 25}), (fn.to_decibels, {}), - (fn.experimental.audio_resample, {'devices': ['cpu'], 'scale': 1.2}), + (fn.audio_resample, {'devices': ['cpu'], 'scale': 1.2}), ] @@ -1261,7 +1261,7 @@ def pipeline(): "random_bbox_crop", "ssd_random_crop", "optical_flow", - "experimental.audio_resample", + "audio_resample", ] excluded_methods = [ diff --git a/dali/test/python/test_eager_coverage.py b/dali/test/python/test_eager_coverage.py index 3b07d4f7cc..cd18b20997 100644 --- a/dali/test/python/test_eager_coverage.py +++ b/dali/test/python/test_eager_coverage.py @@ -489,7 +489,7 @@ def test_to_decibels(): def test_audio_resample(): get_data = GetData(audio_data) - check_single_input('experimental.audio_resample', fn_source=get_data.fn_source, + check_single_input('audio_resample', fn_source=get_data.fn_source, eager_source=get_data.eager_source, layout=None, scale=1.25) @@ -1138,7 +1138,7 @@ def test_batch_permutation(): 'spectrogram', 'mel_filter_bank', 'to_decibels', - 'experimental.audio_resample', + 'audio_resample', 'mfcc', 'one_hot', 'transpose', diff --git a/dali/test/python/test_torch_pipeline_rnnt.py b/dali/test/python/test_torch_pipeline_rnnt.py index 8df2227d23..5b61387504 100644 --- a/dali/test/python/test_torch_pipeline_rnnt.py +++ b/dali/test/python/test_torch_pipeline_rnnt.py @@ -355,7 +355,7 @@ def rnnt_train_pipe(files, # Speed perturbation 0.85x - 1.15x if speed_perturb: target_sr_factor = fn.random.uniform(device="cpu", range=(1 / 1.15, 1 / 0.85)) - audio = fn.experimental.audio_resample(audio, scale=target_sr_factor) + audio = fn.audio_resample(audio, scale=target_sr_factor) # Silence trimming if silence_trim: From d0e0615c891f89d10ca60b76837f168b6867e782 Mon Sep 17 00:00:00 2001 From: Joaquin Anton Date: Thu, 25 Aug 2022 17:12:09 +0200 Subject: [PATCH 2/5] Fix cpu only and variable batch size tests Signed-off-by: Joaquin Anton --- dali/test/python/test_dali_cpu_only.py | 1 + dali/test/python/test_dali_variable_batch_size.py | 1 + 2 files changed, 2 insertions(+) diff --git a/dali/test/python/test_dali_cpu_only.py b/dali/test/python/test_dali_cpu_only.py index 5dbcb869ea..e146cc429e 100644 --- a/dali/test/python/test_dali_cpu_only.py +++ b/dali/test/python/test_dali_cpu_only.py @@ -1243,6 +1243,7 @@ def file_properties(files): "readers.video_resize", # not supported for CPU "optical_flow", # not supported for CPU "paste", # not supported for CPU + "experimental.audio_resample" # Alias of audio_resample (already tested) ] diff --git a/dali/test/python/test_dali_variable_batch_size.py b/dali/test/python/test_dali_variable_batch_size.py index 11ea183e55..5067bfb1ac 100644 --- a/dali/test/python/test_dali_variable_batch_size.py +++ b/dali/test/python/test_dali_variable_batch_size.py @@ -1291,6 +1291,7 @@ def pipeline(): "readers.video_resize", # readers do not support variable batch size yet "readers.webdataset", # readers do not support variable batch size yet "experimental.readers.video", # readers do not support variable batch size yet + "experimental.audio_resample" # Alias of audio_resample (already tested) ] From 0b1734f327bfa799b677584ec20fbea5427b81fd Mon Sep 17 00:00:00 2001 From: Joaquin Anton Date: Fri, 26 Aug 2022 12:40:41 +0200 Subject: [PATCH 3/5] Code review fixes Signed-off-by: Joaquin Anton --- dali/operators/audio/resample.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dali/operators/audio/resample.cc b/dali/operators/audio/resample.cc index 4464dbf41e..c37be1f146 100644 --- a/dali/operators/audio/resample.cc +++ b/dali/operators/audio/resample.cc @@ -101,11 +101,12 @@ DALI_SCHEMA(experimental__AudioResample) .AddParent("AudioResample") .NumInput(1) .NumOutput(1) + .MakeDocPartiallyHidden() .Deprecate( "AudioResample", - R"code(This is just an deprecated alias kept for backward compatibility.)code"); // Deprecated - // in 1.18 - + "This operator was moved out from the experimental phase, " + "and is now regular DALI operator. This is just an deprecated " + "alias kept for backward compatibility."); // Deprecated in 1.18 namespace audio { From 317929344ae5d7337cbed0997e95b7c9c8390828 Mon Sep 17 00:00:00 2001 From: Joaquin Anton Date: Fri, 26 Aug 2022 12:44:51 +0200 Subject: [PATCH 4/5] Add docstr Signed-off-by: Joaquin Anton --- dali/operators/audio/resample.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/dali/operators/audio/resample.cc b/dali/operators/audio/resample.cc index c37be1f146..f21ec9bcd9 100644 --- a/dali/operators/audio/resample.cc +++ b/dali/operators/audio/resample.cc @@ -99,6 +99,7 @@ type. Example:: // Deprecated alias DALI_SCHEMA(experimental__AudioResample) .AddParent("AudioResample") + .DocStr("Legacy alias for :meth:`audio_resample`.") .NumInput(1) .NumOutput(1) .MakeDocPartiallyHidden() From edd48c0bd62cb9b5fdfd47c936e34f142d416e4c Mon Sep 17 00:00:00 2001 From: Joaquin Anton Date: Fri, 26 Aug 2022 12:48:43 +0200 Subject: [PATCH 5/5] grammar fix Signed-off-by: Joaquin Anton --- dali/operators/audio/resample.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dali/operators/audio/resample.cc b/dali/operators/audio/resample.cc index f21ec9bcd9..17eba6898e 100644 --- a/dali/operators/audio/resample.cc +++ b/dali/operators/audio/resample.cc @@ -106,7 +106,7 @@ DALI_SCHEMA(experimental__AudioResample) .Deprecate( "AudioResample", "This operator was moved out from the experimental phase, " - "and is now regular DALI operator. This is just an deprecated " + "and is now a regular DALI operator. This is just an deprecated " "alias kept for backward compatibility."); // Deprecated in 1.18 namespace audio {