tensorflow/models · error · ValueError
Wrong shape detected for custom policy. Expected (:, :, 3) b
Error message
Wrong shape detected for custom policy. Expected (:, :, 3) but got {}. What it means
Error "Wrong shape detected for custom policy. Expected (:, :, 3) but got {}." thrown in tensorflow/models.
Source
Thrown at official/vision/ops/augment.py:2006
self.policies = self.available_policies[augmentation_name]
else:
self._check_policy_shape(policies)
self.policies = policies
def _check_policy_shape(self, policies):
"""Checks dimension and shape of the custom policy.
Args:
policies: List of list of tuples in the form `(func, prob, level)`. Must
have shape of `(:, :, 3)`.
Raises:
ValueError if the shape of `policies` is unexpected.
"""
in_shape = np.array(policies).shape
if len(in_shape) != 3 or in_shape[-1:] != (3,):
raise ValueError('Wrong shape detected for custom policy. Expected '
'(:, :, 3) but got {}.'.format(in_shape))
def _make_tf_policies(self):
"""Prepares the TF functions for augmentations based on the policies."""
replace_value = [128] * 3
# func is the string name of the augmentation function, prob is the
# probability of applying the operation and level is the parameter
# associated with the tf op.
# tf_policies are functions that take in an image and return an augmented
# image.
tf_policies = []
for policy in self.policies:
tf_policy = []
assert_ranges = []
# Link string name to the correct python function and make sure the
# correct argument is passed into that function.View on GitHub (pinned to e006f5f0d5)
Solutions
- Shape the custom policy array as (:, :, 3): each sub-policy is a list of (op, prob, magnitude) triples.
- Fix the custom policy structure so every operation entry has exactly 3 elements.
When it happens
Trigger: Thrown at official/vision/ops/augment.py:2006 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/db4698e65f312ac6.
Report an issue: GitHub.