tensorflow/models · error · ValueError

Number of output filters must be even to ensure splitting in

Error message

Number of output filters must be even to ensure splitting in channel dimension for reversible blocks

What it means

Error "Number of output filters must be even to ensure splitting in channel dimension for reversible blocks" thrown in tensorflow/models.

Source

Thrown at official/vision/modeling/backbones/revnet.py:125

    x = self._norm(
        axis=axis,
        momentum=norm_momentum,
        epsilon=norm_epsilon,
        synchronized=use_sync_bn)(x)
    x = tf_utils.get_activation(activation)(x)
    x = tf_keras.layers.MaxPool2D(pool_size=3, strides=2, padding='same')(x)

    endpoints = {}
    for i, spec in enumerate(REVNET_SPECS[model_id]):
      if spec[0] == 'residual':
        inner_block_fn = nn_blocks.ResidualInner
      elif spec[0] == 'bottleneck':
        inner_block_fn = nn_blocks.BottleneckResidualInner
      else:
        raise ValueError('Block fn `{}` is not supported.'.format(spec[0]))

      if spec[1] % 2 != 0:
        raise ValueError('Number of output filters must be even to ensure '
                         'splitting in channel dimension for reversible blocks')

      x = self._block_group(
          inputs=x,
          filters=spec[1],
          strides=(1 if i == 0 else 2),
          inner_block_fn=inner_block_fn,
          block_repeats=spec[2],
          batch_norm_first=(i != 0),  # Only skip on first block
          name='revblock_group_{}'.format(i + 2))
      endpoints[str(i + 2)] = x

    self._output_specs = {l: endpoints[l].get_shape() for l in endpoints}

    super(RevNet, self).__init__(inputs=inputs, outputs=endpoints, **kwargs)

  def _block_group(self,
                   inputs: tf.Tensor,

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Set the stage's filters to an even number so channels can be split for the reversible block.
  2. Halve an odd filter count or round it to the nearest even value in the backbone config.

When it happens

Trigger: Thrown at official/vision/modeling/backbones/revnet.py:125 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/2a0da6ad00086f1e. Report an issue: GitHub.