votes up 8

sample_rate must be positive. Got: %s

Package:
Exception Class:
ValueError

Raise code

    raise ValueError('lower_edge_hertz must be non-negative. Got: %s' %
                     lower_edge_hertz)
  if lower_edge_hertz >= upper_edge_hertz:
    raise ValueError('lower_edge_hertz %.1f >= upper_edge_hertz %.1f' %
                     (lower_edge_hertz, upper_edge_hertz))
  if not isinstance(sample_rate, ops.Tensor):
    if sample_rate <= 0.0:
      raise ValueError('sample_rate must be positive. Got: %s' % sample_rate)
    if upper_edge_hertz > sample_rate / 2:
      raise ValueError('upper_edge_hertz must not be larger than the Nyquist '
                       'frequency (sample_rate / 2). Got %s for sample_rate: %s'
                       % (upper_edge_hertz, sample_rate))
  if not dtype.is_floating:
    raise ValueError('dtype must be a floating point type. Got: %s' % dtype)
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 2 votes down

The sample_rate parameter of the linear_to_mel_weight_matrix should be greater than zero.

Reproducing the error:

pipenv install tensorflow

from tensorflow.signal import linear_to_mel_weight_matrix
result = linear_to_mel_weight_matrix(num_mel_bins=30,
                                               sample_rate=0)
print(result.shape)

The error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-4abec9fddd07> in <module>()
      1 from tensorflow.signal import linear_to_mel_weight_matrix
      2 result = linear_to_mel_weight_matrix(num_mel_bins=30,
----> 3                                                sample_rate=0)
      4 print(result.shape)

/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
    204     """Call target, and fall back on dispatchers if there is a TypeError."""
    205     try:
--> 206       return target(*args, **kwargs)
    207     except (TypeError, ValueError):
    208       # Note: convert_to_eager_tensor currently raises a ValueError, not a

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/signal/mel_ops.py in linear_to_mel_weight_matrix(num_mel_bins, num_spectrogram_bins, sample_rate, lower_edge_hertz, upper_edge_hertz, dtype, name)
    170     # and in kernel), there is no need to validate num_spectrogram_bins here.
    171     _validate_arguments(num_mel_bins, sample_rate,
--> 172                         lower_edge_hertz, upper_edge_hertz, dtype)
    173 
    174     # This function can be constant folded by graph optimization since there are

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/signal/mel_ops.py in _validate_arguments(num_mel_bins, sample_rate, lower_edge_hertz, upper_edge_hertz, dtype)
     82   if not isinstance(sample_rate, ops.Tensor):
     83     if sample_rate <= 0.0:
---> 84       raise ValueError('sample_rate must be positive. Got: %s' % sample_rate)
     85     if upper_edge_hertz > sample_rate / 2:
     86       raise ValueError('upper_edge_hertz must not be larger than the Nyquist '

ValueError: sample_rate must be positive. Got: 0

The fixed version:

from tensorflow.signal import linear_to_mel_weight_matrix
result = linear_to_mel_weight_matrix(num_mel_bins=30,
                                               sample_rate=8000)
print(result.shape)

Output:

(129, 30)

Jul 16, 2021 kellemnegasi answer
kellemnegasi 31.6k

Add a possible fix

Please authorize to post fix