{"record":{"id":"fc3cdcbff5775345","repo":"open-mmlab/mmdetection","slug":"type-must-be-a-str-or-valid-type-but-got-type-ob","errorCode":null,"errorMessage":"type must be a str or valid type, but got {type(obj_type)}","messagePattern":"type must be a str or valid type, but got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/datasets/transforms/transforms.py","lineNumber":1665,"sourceCode":"\n        Args:\n            cfg (dict): Config dict. It should at least contain the key \"type\".\n\n        Returns:\n            obj: The constructed object.\n        \"\"\"\n\n        assert isinstance(cfg, dict) and 'type' in cfg\n        args = cfg.copy()\n        obj_type = args.pop('type')\n        if is_str(obj_type):\n            if albumentations is None:\n                raise RuntimeError('albumentations is not installed')\n            obj_cls = getattr(albumentations, obj_type)\n        elif inspect.isclass(obj_type):\n            obj_cls = obj_type\n        else:\n            raise TypeError(\n                f'type must be a str or valid type, but got {type(obj_type)}')\n\n        if 'transforms' in args:\n            args['transforms'] = [\n                self.albu_builder(transform)\n                for transform in args['transforms']\n            ]\n\n        return obj_cls(**args)\n\n    @staticmethod\n    def mapper(d: dict, keymap: dict) -> dict:\n        \"\"\"Dictionary mapper. Renames keys according to keymap provided.\n\n        Args:\n            d (dict): old dict\n            keymap (dict): {'old_key':'new_key'}\n        Returns:","sourceCodeStart":1647,"sourceCodeEnd":1683,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/datasets/transforms/transforms.py#L1647-L1683","documentation":"Albu.albu_builder requires each transform entry's 'type' to be either a string (albumentations transform name) or a class. Any other type (int, dict, list, None) raises TypeError.","triggerScenarios":"Writing dict(type=3), type=None, type=[...], or a nested dict in the 'type' field of an entry inside Albu transforms or keymap-driven builder input.","commonSituations":"Hand-editing Albu configs and putting a dict/list into 'type'; YAML quoting issues turning a name into another structure.","solutions":["Set 'type' to a valid albumentations transform name string, e.g. 'HorizontalFlip'","Or pass the actual class object: dict(type=albumentations.HorizontalFlip)","Check YAML quoting of the type value"],"exampleFix":"# before\ndict(type=Albu, transforms=[dict(type=dict(name='Blur'), p=0.1)])\n# after\ndict(type='Albu', transforms=[dict(type='Blur', p=0.1)])","handlingStrategy":"type-guard","validationCode":"for t in albu_cfg['transforms']:\n    assert isinstance(t['type'], str) or inspect.isclass(t['type']), f\"bad type: {t['type']!r}\"","typeGuard":"import inspect\ndef valid_albu_type(v):\n    return isinstance(v, str) or inspect.isclass(v)","tryCatchPattern":"try:\n    Albu(transforms=cfg)\nexcept TypeError as e:\n    if 'type must be a str' in str(e):\n        fix_and_retry()","preventionTips":["Validate config schema before building","Use string names exactly matching albumentations transforms"],"tags":["mmdet","albumentations","config-validation","typeerror"],"backgroundTag":"config-type-validation-failed","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}