facebookresearch/detectron2 · error · TypeError
Unsupported type for argument `serailzie`: {serialize}
Error message
Unsupported type for argument `serailzie`: {serialize} What it means
Raised by SerializeList's __init__ when the `serialize` argument is neither a bool nor a callable. The class uses `serialize` to decide whether to serialize list elements (and optionally accepts a custom serializer callable); any other type (e.g. a string like 'w' or an int) is rejected.
Source
Thrown at detectron2/data/common.py:229
self,
lst: list,
copy: bool = True,
serialize: Union[bool, Callable] = True,
):
"""
Args:
lst (list): a list which contains elements to produce.
copy (bool): whether to deepcopy the element when producing it,
so that the result can be modified in place without affecting the
source in the list.
serialize (bool or callable): whether to serialize the stroage to other
backend. If `True`, the default serialize method will be used, if given
a callable, the callable will be used as serialize method.
"""
self._lst = lst
self._copy = copy
if not isinstance(serialize, (bool, Callable)):
raise TypeError(f"Unsupported type for argument `serailzie`: {serialize}")
self._serialize = serialize is not False
if self._serialize:
serialize_method = (
serialize
if isinstance(serialize, Callable)
else _DEFAULT_DATASET_FROM_LIST_SERIALIZE_METHOD
)
logger.info(f"Serializing the dataset using: {serialize_method}")
self._lst = serialize_method(self._lst)
def __len__(self):
return len(self._lst)
def __getitem__(self, idx):
if self._copy and not self._serialize:
return copy.deepcopy(self._lst[idx])
else:View on GitHub (pinned to a2f4a8771a)
Solutions
- Pass a bool: SerializeList(lst, serialize=True) or serialize=False
- Or pass a callable used as the serialize method, e.g. SerializeList(lst, serialize=pickle.dumps)
- If forwarding a config value, validate it before constructing: assert isinstance(cfg.serialize, (bool, Callable))
Example fix
// before srl = SerializeList(lst, serialize='w') // after srl = SerializeList(lst, serialize=True)
Defensive patterns
Strategy: type-guard
Validate before calling
from typing import Callable
assert serialize is None or isinstance(serialize, (bool, Callable)), \
f"serialize must be bool or Callable, got {type(serialize)}" Type guard
def is_valid_serialize(x) -> bool:
return isinstance(x, bool) or callable(x) Prevention
- Validate the serialize argument at config-parse time
- Never pass file-mode strings; this API accepts only bool or callable
When it happens
Trigger: Constructing SerializeList(lst, serialize=<non-bool-non-callable>) e.g. SerializeList(data, serialize='w') or serialize=1; typically hit when passing an open-mode-like string or file object where a bool/callable was expected, or when a variable of the wrong type is forwarded from user config.
Common situations: Copy-pasting a torch.utils.data style API where an argument like a file mode string is accepted; passing a serialization function object that is actually None or a string; version changes where the constructor signature changed.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- Unknown segmentation type {type(segmentation)}!
- Cannot match one checkpoint key to multiple keys in the mode
- Class with @configurable must have a 'from_config' classmeth
- {name} must take 'cfg' as the first argument!
- target of LazyCall must be a callable or defines a callable!
AI-assisted analysis of facebookresearch/detectron2@a2f4a8771a (2026-08-27).
Data as JSON: /api/errors/150629661a872b91.
Report an issue: GitHub.