roboflow/supervision · error · ValueError
Areas must be shaped (N,)
Error message
Areas must be shaped (N,)
What it means
Raised by get_area_size_category() when the areas array is not one-dimensional. The function maps each scalar area to a size bucket via boolean masks, so a 2-D input (e.g. an (N,1) column) breaks the elementwise bucketing. Validation happens before the thresholds are applied.
Source
Thrown at src/supervision/metrics/utils/object_size.py:156
Returns:
The size category of each area, matching the enum values of
`ObjectSizeCategory`. Shaped (N,).
Raises:
ValueError: If `areas` is not one-dimensional.
Example:
```pycon
>>> import numpy as np
>>> from supervision.metrics.utils.object_size import get_area_size_category
>>> get_area_size_category(np.array([100, 2500, 10000]))
array([1, 2, 3])
```
"""
if len(areas.shape) != 1:
raise ValueError("Areas must be shaped (N,)")
result = np.full(areas.shape, ObjectSizeCategory.ANY.value)
sm, lg = SIZE_THRESHOLDS
result[areas < sm] = ObjectSizeCategory.SMALL.value
result[(areas >= sm) & (areas < lg)] = ObjectSizeCategory.MEDIUM.value
result[areas >= lg] = ObjectSizeCategory.LARGE.value
return result
def get_mask_size_category(
mask: npt.NDArray[np.bool_] | CompactMask,
) -> npt.NDArray[np.int_]:
"""
Get the size category of detection masks.
Args:
mask: The mask array shaped (N, H, W), or a
:class:`~supervision.detection.compact_mask.CompactMask`.View on GitHub (pinned to 7f254d9784)
Solutions
- Flatten before calling: np.asarray(areas).reshape(-1) or .ravel()
- Use single brackets when extracting from DataFrames: df['area'].values
- Avoid keepdims=True on the reduction that produces the areas
Example fix
# before areas = df[['area']].to_numpy() # (N, 1) get_area_size_category(areas) # ValueError # after areas = df['area'].to_numpy() # (N,) get_area_size_category(areas)
Defensive patterns
Strategy: validation
Validate before calling
areas = np.asarray(areas).reshape(-1)
if areas.ndim != 1:
raise ValueError('areas must be 1-D')
cats = get_area_size_category(areas) Type guard
import numpy as np
def is_flat_vector(arr: np.ndarray) -> bool:
"""True when arr is one-dimensional."""
return arr.ndim == 1 Try / catch
try:
cats = get_area_size_category(areas)
except ValueError as e:
if 'shaped (N,)' in str(e):
cats = get_area_size_category(np.asarray(areas).ravel())
else:
raise Prevention
- Use df['col'].to_numpy() (single brackets) rather than df[['col']].to_numpy()
- Avoid keepdims=True on reductions that feed per-item arrays into metrics
When it happens
Trigger: Calling get_area_size_category with areas shaped (N, 1) (common after np.sum(..., keepdims=True) or df[['area']].values), or with a scalar 0-D array.
Common situations: Areas extracted from a pandas DataFrame with double brackets producing (N,1); results of reductions with keepdims=True; nested lists passed directly instead of flattened.
Related errors
- Bounding boxes must be shaped (N, 4)
- Confusion matrix must have shape (..., 3), got {confusion_ma
- Oriented bounding boxes must be shaped (N, 4, 2)
- Masks must be shaped (N, H, W)
- Value must be a np.ndarray or a list
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/a42c18538ce09df3.
Report an issue: GitHub.