tensorflow/models · error · ValueError

Initial drop rate must be within 0 and 1.

Error message

Initial drop rate must be within 0 and 1.

What it means

Error "Initial drop rate must be within 0 and 1." thrown in tensorflow/models.

Source

Thrown at official/vision/modeling/layers/nn_layers.py:219

    x = self._activation_fn(self._se_reduce(x))
    x = self._gating_activation_fn(self._se_expand(x))
    return x * inputs


def get_stochastic_depth_rate(init_rate, i, n):
  """Get drop connect rate for the ith block.

  Args:
    init_rate: A `float` of initial drop rate.
    i: An `int` of order of the current block.
    n: An `int` total number of blocks.

  Returns:
    Drop rate of the ith block.
  """
  if init_rate is not None:
    if init_rate < 0 or init_rate > 1:
      raise ValueError('Initial drop rate must be within 0 and 1.')
    rate = init_rate * float(i) / n
  else:
    rate = None
  return rate


@tf_keras.utils.register_keras_serializable(package='Vision')
class StochasticDepth(tf_keras.layers.Layer):
  """Creates a stochastic depth layer."""

  def __init__(self, stochastic_depth_drop_rate, **kwargs):
    """Initializes a stochastic depth layer.

    Args:
      stochastic_depth_drop_rate: A `float` of drop rate.
      **kwargs: Additional keyword arguments to be passed.

    Returns:

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Set the initial drop rate to a value in [0, 1].
  2. Check the stochastic depth drop rate config for an out-of-range value.

When it happens

Trigger: Thrown at official/vision/modeling/layers/nn_layers.py:219 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24). Data as JSON: /api/errors/432cfc34d50f3722. Report an issue: GitHub.