{"record":{"id":"376b2a28317f0844","repo":"open-mmlab/mmdetection","slug":"invalid-crop-type-crop-type","errorCode":null,"errorMessage":"Invalid crop_type {crop_type}.","messagePattern":"Invalid crop_type (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/datasets/transforms/transforms.py","lineNumber":858,"sourceCode":"            original image.\n        - The keys for bboxes, labels and masks must be aligned. That is,\n          ``gt_bboxes`` corresponds to ``gt_labels`` and ``gt_masks``, and\n          ``gt_bboxes_ignore`` corresponds to ``gt_labels_ignore`` and\n          ``gt_masks_ignore``.\n        - If the crop does not contain any gt-bbox region and\n          ``allow_negative_crop`` is set to False, skip this image.\n    \"\"\"\n\n    def __init__(self,\n                 crop_size: tuple,\n                 crop_type: str = 'absolute',\n                 allow_negative_crop: bool = False,\n                 recompute_bbox: bool = False,\n                 bbox_clip_border: bool = True) -> None:\n        if crop_type not in [\n                'relative_range', 'relative', 'absolute', 'absolute_range'\n        ]:\n            raise ValueError(f'Invalid crop_type {crop_type}.')\n        if crop_type in ['absolute', 'absolute_range']:\n            assert crop_size[0] > 0 and crop_size[1] > 0\n            assert isinstance(crop_size[0], int) and isinstance(\n                crop_size[1], int)\n            if crop_type == 'absolute_range':\n                assert crop_size[0] <= crop_size[1]\n        else:\n            assert 0 < crop_size[0] <= 1 and 0 < crop_size[1] <= 1\n        self.crop_size = crop_size\n        self.crop_type = crop_type\n        self.allow_negative_crop = allow_negative_crop\n        self.bbox_clip_border = bbox_clip_border\n        self.recompute_bbox = recompute_bbox\n\n    def _crop_data(self, results: dict, crop_size: Tuple[int, int],\n                   allow_negative_crop: bool) -> Union[dict, None]:\n        \"\"\"Function to randomly crop images, bounding boxes, masks, semantic\n        segmentation maps.","sourceCodeStart":840,"sourceCodeEnd":876,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/datasets/transforms/transforms.py#L840-L876","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ndict(type='RandomCrop', crop_size=(0.5, 0.5), crop_type='relative-range')\n# after\ndict(type='RandomCrop', crop_size=(0.5, 0.5), crop_type='relative_range')","handlingStrategy":"validation","validationCode":"VALID = {'relative_range', 'relative', 'absolute', 'absolute_range'}\nassert cfg['crop_type'] in VALID, f\"crop_type must be one of {VALID}\"","typeGuard":"def is_valid_crop_type(ct: str) -> bool:\n    return ct in {'relative_range', 'relative', 'absolute', 'absolute_range'}","tryCatchPattern":null,"preventionTips":["Copy crop_type values verbatim from official mmdet crop configs","Validate pipeline dicts against a whitelist of enum values before building the dataset"],"tags":["mmdetection","random-crop","valueerror","config-validation","augmentation"],"backgroundTag":"invalid-enum-value","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}