open-mmlab/mmdetection · error · ValueError
Invalid crop_type {crop_type}.
Error message
Invalid crop_type {crop_type}. What it means
RandomCrop's __init__ validates crop_type against the four supported modes: 'relative_range', 'relative', 'absolute', 'absolute_range'. Any other string (typos like 'abs', 'relative-range', 'Absolute', or empty) raises ValueError immediately at pipeline construction.
Source
Thrown at mmdet/datasets/transforms/transforms.py:858
original image.
- The keys for bboxes, labels and masks must be aligned. That is,
``gt_bboxes`` corresponds to ``gt_labels`` and ``gt_masks``, and
``gt_bboxes_ignore`` corresponds to ``gt_labels_ignore`` and
``gt_masks_ignore``.
- If the crop does not contain any gt-bbox region and
``allow_negative_crop`` is set to False, skip this image.
"""
def __init__(self,
crop_size: tuple,
crop_type: str = 'absolute',
allow_negative_crop: bool = False,
recompute_bbox: bool = False,
bbox_clip_border: bool = True) -> None:
if crop_type not in [
'relative_range', 'relative', 'absolute', 'absolute_range'
]:
raise ValueError(f'Invalid crop_type {crop_type}.')
if crop_type in ['absolute', 'absolute_range']:
assert crop_size[0] > 0 and crop_size[1] > 0
assert isinstance(crop_size[0], int) and isinstance(
crop_size[1], int)
if crop_type == 'absolute_range':
assert crop_size[0] <= crop_size[1]
else:
assert 0 < crop_size[0] <= 1 and 0 < crop_size[1] <= 1
self.crop_size = crop_size
self.crop_type = crop_type
self.allow_negative_crop = allow_negative_crop
self.bbox_clip_border = bbox_clip_border
self.recompute_bbox = recompute_bbox
def _crop_data(self, results: dict, crop_size: Tuple[int, int],
allow_negative_crop: bool) -> Union[dict, None]:
"""Function to randomly crop images, bounding boxes, masks, semantic
segmentation maps.View on GitHub (pinned to cfd5d3a985)
Solutions
- Set crop_type to one of 'relative_range' (default), 'relative', 'absolute', or 'absolute_range'
- Remember semantics: 'relative*' treats crop_size as fractions of image size, 'absolute*' as pixels, 'absolute_range' picks a random size up to crop_size
Example fix
# before dict(type='RandomCrop', crop_size=(0.5, 0.5), crop_type='relative-range') # after dict(type='RandomCrop', crop_size=(0.5, 0.5), crop_type='relative_range')
Defensive patterns
Strategy: validation
Validate before calling
VALID = {'relative_range', 'relative', 'absolute', 'absolute_range'}
assert cfg['crop_type'] in VALID, f"crop_type must be one of {VALID}" Type guard
def is_valid_crop_type(ct: str) -> bool:
return ct in {'relative_range', 'relative', 'absolute', 'absolute_range'} Prevention
- Copy crop_type values verbatim from official mmdet crop configs
- Validate pipeline dicts against a whitelist of enum values before building the dataset
When it happens
Trigger: Building dict(type='RandomCrop', crop_size=(w, h), crop_type='...') with a crop_type not exactly one of the four allowed lowercase strings; the check is an exact membership test so case and spelling must match.
Common situations: Hand-written configs with typo'd or translated crop_type values; porting crop configs from other libraries (e.g. albumentations 'px'/'percent' vocabulary) into mmdet; copy-paste from outdated docs.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid scale {scale}, must be positive.
- Please run "pip install instaboostfast" to install instaboos
- Please run "pip install instaboostfast" to install instaboos
- Scale must be a number or tuple of int, but got {type(scale)
- basesize_ratio_range[0] should be either 0.15or 0.2 when inp
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/376b2a28317f0844.
Report an issue: GitHub.