{"record":{"id":"b0e6a8ccf0c10ef3","repo":"open-mmlab/mmdetection","slug":"unsupported-type-mask-data-type","errorCode":null,"errorMessage":"Unsupported {type(mask)} data type","messagePattern":"Unsupported (.+?) data type","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/models/utils/misc.py","lineNumber":250,"sourceCode":"    return ret\n\n\ndef mask2ndarray(mask):\n    \"\"\"Convert Mask to ndarray..\n\n    Args:\n        mask (:obj:`BitmapMasks` or :obj:`PolygonMasks` or\n        torch.Tensor or np.ndarray): The mask to be converted.\n\n    Returns:\n        np.ndarray: Ndarray mask of shape (n, h, w) that has been converted\n    \"\"\"\n    if isinstance(mask, (BitmapMasks, PolygonMasks)):\n        mask = mask.to_ndarray()\n    elif isinstance(mask, torch.Tensor):\n        mask = mask.detach().cpu().numpy()\n    elif not isinstance(mask, np.ndarray):\n        raise TypeError(f'Unsupported {type(mask)} data type')\n    return mask\n\n\ndef flip_tensor(src_tensor, flip_direction):\n    \"\"\"flip tensor base on flip_direction.\n\n    Args:\n        src_tensor (Tensor): input feature map, shape (B, C, H, W).\n        flip_direction (str): The flipping direction. Options are\n          'horizontal', 'vertical', 'diagonal'.\n\n    Returns:\n        out_tensor (Tensor): Flipped tensor.\n    \"\"\"\n    assert src_tensor.ndim == 4\n    valid_directions = ['horizontal', 'vertical', 'diagonal']\n    assert flip_direction in valid_directions\n    if flip_direction == 'horizontal':","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/utils/misc.py#L232-L268","documentation":"mask2ndarray converts mask representations (BitmapMasks, PolygonMasks, Tensor, ndarray) to a numpy array. Any other Python type hits the TypeError branch — the function does not accept lists of masks, RLE strings, or other objects.","triggerScenarios":"Passing e.g. a list of per-instance numpy arrays, an RLE dict/string, a PIL Image, or None as the mask argument to mask2ndarray.","commonSituations":"Feeding custom dataset outputs directly into loss/metric code that expects a mmdet mask structure; converting from pycocotools RLE without first decoding to ndarray.","solutions":["Wrap raw masks: np.stack(list_of_arrays) or pass a single ndarray of shape (N, H, W)","Convert RLE with pycocotools.mask.decode first","Wrap instance masks as BitmapMasks(masks, h, w) or PolygonMasks(...) for structured pipelines"],"exampleFix":"# before\nmask2ndarray([arr1, arr2])  # list -> TypeError\n# after\nmask2ndarray(np.stack([arr1, arr2]))","handlingStrategy":"type-guard","validationCode":"import numpy as np, torch\nfrom mmdet.structures import BitmapMasks\nassert isinstance(mask, (np.ndarray, torch.Tensor, list, tuple)) or hasattr(mask, 'to_ndarray')","typeGuard":"def is_mask2ndarray_input(m) -> bool:\n    return (isinstance(m, (np.ndarray, torch.Tensor))\n            or isinstance(m, (list, tuple))\n            or hasattr(m, 'to_ndarray'))","tryCatchPattern":"try:\n    arr = mask2ndarray(mask)\nexcept TypeError:\n    arr = mask2ndarray(BitmapMasks([np.asarray(m) for m in mask], h, w))","preventionTips":["Normalize masks to BitmapMasks/ndarray at dataset boundaries","Decode RLE with pycocotools before passing masks around"],"tags":["mmdetection","mask","type-validation"],"backgroundTag":"unsupported-type","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}