From 639a68d2aee94a83641491becabf0e5aa39aee96 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Thu, 27 Feb 2020 18:34:23 +0100 Subject: [PATCH] Ensure sample rate comparison with proper types Fixes #2798 --- util/feeding.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/util/feeding.py b/util/feeding.py index 2c33d2ae..3e21427f 100644 --- a/util/feeding.py +++ b/util/feeding.py @@ -31,8 +31,13 @@ def read_csvs(csv_files): def samples_to_mfccs(samples, sample_rate, train_phase=False, wav_filename=None): - if train_phase and sample_rate != FLAGS.audio_sample_rate: - tf.print('WARNING: sample rate of file', wav_filename, '(', sample_rate, ') does not match FLAGS.audio_sample_rate. This can lead to incorrect results.') + if train_phase: + # We need the lambdas to make TensorFlow happy. + # pylint: disable=unnecessary-lambda + tf.cond(tf.math.not_equal(sample_rate, FLAGS.audio_sample_rate), + lambda: tf.print('WARNING: sample rate of file', wav_filename, '(', sample_rate, ') does not match FLAGS.audio_sample_rate. This can lead to incorrect results.'), + lambda: tf.no_op(), + name='matching_sample_rate') spectrogram = contrib_audio.audio_spectrogram(samples, window_size=Config.audio_window_samples,