huggingface/pytorch-image-models · warning

CSATv2 is designed for 3-channel RGB input. in_chans={in_cha

Error message

CSATv2 is designed for 3-channel RGB input. in_chans={in_chans} may not work correctly with the DCT stem.

What it means

The CSATv2 architecture uses a DCT-based stem tuned for 3-channel RGB input; instantiating it with a different in_chans triggers this warning that behavior may be incorrect. It is a heads-up, not a hard failure — the model still builds.

Source

Thrown at timm/models/csatv2.py:563

    def __init__(
            self,
            num_classes: int = 1000,
            in_chans: int = 3,
            dims: Tuple[int, ...] = (32, 72, 168, 386),
            depths: Tuple[int, ...] = (2, 2, 8, 6),
            transformer_depths: Tuple[int, ...] = (0, 0, 2, 2),
            drop_path_rate: float = 0.0,
            transformer_drop_path: bool = False,
            ls_init_value: Optional[float] = None,
            global_pool: str = 'avg',
            device=None,
            dtype=None,
            **kwargs,
    ) -> None:
        dd = dict(device=device, dtype=dtype)
        super().__init__()
        if in_chans != 3:
            warnings.warn(
                f'CSATv2 is designed for 3-channel RGB input. '
                f'in_chans={in_chans} may not work correctly with the DCT stem.'
            )
        self.num_classes = num_classes
        self.in_chans = in_chans
        self.global_pool = global_pool
        self.grad_checkpointing = False

        self.num_features = dims[-1]
        self.head_hidden_size = self.num_features

        # Build feature_info dynamically
        self.feature_info = [dict(num_chs=dims[0], reduction=8, module='stem_dct')]
        reduction = 8
        for i, dim in enumerate(dims):
            if i > 0:
                reduction *= 2
            self.feature_info.append(dict(num_chs=dim, reduction=reduction, module=f'stages.{i}'))

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Convert your input to 3-channel RGB before the model (repeat/interpolate channels) and keep in_chans=3
  2. If channel mismatch is required, verify the DCT stem actually supports it — test forward pass output sanity
  3. Use a model with a standard conv stem if single-channel input is a hard requirement

Example fix

# before
model = timm.create_model('csatv2_tiny', in_chans=1, pretrained=True)
# after
model = timm.create_model('csatv2_tiny', in_chans=3, pretrained=True)
x = x.repeat(1, 3, 1, 1)  # grayscale -> RGB
Defensive patterns

Strategy: validation

Validate before calling

in_chans = 1
if in_chans != 3:
    raise ValueError('CSATv2 expects 3-channel RGB input; convert input or pick another model')
model = timm.create_model('csatv2_tiny', in_chans=in_chans, pretrained=True)

Prevention

When it happens

Trigger: Passing in_chans=1 (grayscale), in_chans=4, or other values != 3 to csatv2_tiny/small/base or via timm.create_model('csatv2_*', in_chans=...).

Common situations: Reusing pretrained CSATv2 weights on grayscale medical/satellite imagery, or adding an alpha channel by accident; fine-tuning scripts that blanket-set in_chans for all models.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/5bbae6a720b08323. Report an issue: GitHub.