tensorflow/models · error · ValueError

The number of input channels must be divisible by the number

Error message

The number of input channels must be divisible by the number of groups for evenly group split.

What it means

Error "The number of input channels must be divisible by the number of groups for evenly group split." thrown in tensorflow/models.

Source

Thrown at official/projects/mosaic/qat/modeling/layers/nn_blocks.py:43

from official.projects.qat.vision.quantization import helper


@tf_keras.utils.register_keras_serializable(package='Vision')
class MultiKernelGroupConvBlockQuantized(mosaic_blocks.MultiKernelGroupConvBlock
                                        ):
  """A quantized multi-kernel grouped convolution block.

  This block is used in the segmentation neck introduced in MOSAIC.
  Reference:
   [MOSAIC: Mobile Segmentation via decoding Aggregated Information and encoded
   Context](https://arxiv.org/pdf/2112.11623.pdf)
  """

  def build(self, input_shape: tf.TensorShape) -> None:
    """Builds the block with the given input shape."""
    input_channels = input_shape[self._group_split_axis]
    if input_channels % self._num_groups != 0:
      raise ValueError('The number of input channels must be divisible by '
                       'the number of groups for evenly group split.')

    # Override the activation and bn with their quantized version.
    self._activation_fn = tfmot.quantization.keras.QuantizeWrapperV2(
        tf_utils.get_activation(self._activation, use_keras_layer=True),
        configs.Default8BitActivationQuantizeConfig())
    norm_layer = (
        tf_keras.layers.experimental.SyncBatchNormalization
        if self._use_sync_bn else tf_keras.layers.BatchNormalization)
    norm_with_quantize = helper.BatchNormalizationQuantized(norm_layer)
    norm_no_quantize = helper.BatchNormalizationNoQuantized(norm_layer)
    self._bn_op = helper.norm_by_activation(
        self._activation, norm_with_quantize, norm_no_quantize)

    self._conv_branches = []
    if self._use_depthwise_convolution:
      for i, conv_kernel_size in enumerate(self._kernel_sizes):
        depthwise_conv = helper.DepthwiseConv2DQuantized(

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/mosaic/qat/modeling/layers/nn_blocks.py:43 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/6958acadd2360d45. Report an issue: GitHub.