tensorflow/models · error · ValueError
Unsupported pooling strategy
Error message
Unsupported pooling strategy: {pooling!r}. Expected one of {SUPPORTED_POOLING_STRATEGIES}. What it means
Validation in Dinov3ClassificationModule.__init__: the pooling argument selects how backbone features are aggregated into the classification head, and only strategies listed in SUPPORTED_POOLING_STRATEGIES (CLS and CLS_MEAN_PATCH) have head implementations. An unrecognized value — a typo or a raw string not in the enum — has no code path, so construction aborts before the head is built.
Solutions
- Use one of the supported values from SUPPORTED_POOLING_STRATEGIES, e.g. PoolingStrategy.CLS or PoolingStrategy.CLS_MEAN_PATCH
- Import the PoolingStrategy enum instead of passing raw strings
- Print SUPPORTING_POOLING_STRATEGIES or check the module constants to confirm valid options
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/projects/waste_identification_ml/fine_tuning/Dinov3_image_classifier/models.py:154 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/8f588139aa3b8b5b.
Report an issue: GitHub.
Appendix: source
Thrown at official/projects/waste_identification_ml/fine_tuning/Dinov3_image_classifier/models.py:154
"""Initializes the DINOv3 classifier with an already-loaded backbone.
Args:
backbone_model: The pre-loaded DINOv3 backbone module (`nn.Module`). Note
that if `fine_tune=False`, the parameters of `backbone_model` are
modified in-place (`requires_grad=False`).
number_of_classes: Number of output classes.
pooling: Feature extraction strategy. One of
`SUPPORTED_POOLING_STRATEGIES`.
fine_tune: If True, backbone parameters remain trainable. If False, they
are frozen.
Raises:
ValueError: If `pooling` is not a supported strategy.
"""
super().__init__()
if pooling not in SUPPORTED_POOLING_STRATEGIES:
raise ValueError(
f"Unsupported pooling strategy: {pooling!r}. "
f"Expected one of {SUPPORTED_POOLING_STRATEGIES}."
)
self.pooling = pooling
self.backbone_model = backbone_model
backbone_hidden_size = self.backbone_model.norm.normalized_shape[0]
if pooling == POOLING_CLS:
head_input_features = backbone_hidden_size
else:
# 'cls_mean_patch' concatenates two vectors of size
# backbone_hidden_size.
head_input_features = 2 * backbone_hidden_size
self.head = nn.Linear(
in_features=head_input_features,
out_features=number_of_classes,View on GitHub (pinned to e006f5f0d5)