open-mmlab/mmdetection · error · ValueError
Invalid text mode "{self.text_mode}".
Error message
Invalid text mode "{self.text_mode}". What it means
RefCoco dataset in mmdet supports only specific text_mode values for turning the multi-sentence referring expressions of a region into training text. After handling 'select_first' and 'original', any other string falls through to this ValueError listing the offending mode.
Source
Thrown at mmdet/datasets/refcoco.py:145
instances = []
sentences = []
for grounding_anno in grounding_dict[img_id]:
texts = [x['raw'].lower() for x in grounding_anno['sentences']]
# random select one text
if self.text_mode == 'random':
idx = random.randint(0, len(texts) - 1)
text = [texts[idx]]
# concat all texts
elif self.text_mode == 'concat':
text = [''.join(texts)]
# select the first text
elif self.text_mode == 'select_first':
text = [texts[0]]
# use all texts
elif self.text_mode == 'original':
text = texts
else:
raise ValueError(f'Invalid text mode "{self.text_mode}".')
ins = [{
'mask': grounding_anno['segmentation'],
'ignore_flag': 0
}] * len(text)
instances.extend(ins)
sentences.extend(text)
data_info = {
'img_path': join_path(img_prefix, image['file_name']),
'img_id': img_id,
'instances': instances,
'text': sentences
}
data_list.append(data_info)
if len(data_list) == 0:
raise ValueError(f'No sample in split "{self.split}".')
return data_listView on GitHub (pinned to cfd5d3a985)
Solutions
- Set text_mode='select_first' to use only the first referring expression per instance
- Set text_mode='original' to keep all referring expressions
- Check the installed mmdet version's refcoco.py for the exact list of supported modes and use one of those
Example fix
# before dataset = dict(type='RefCoco', ann_file=..., data_prefix=..., text_mode='random') # after dataset = dict(type='RefCoco', ann_file=..., data_prefix=..., text_mode='select_first')
Defensive patterns
Strategy: validation
Validate before calling
from mmdet.datasets import RefCoco
VALID_TEXT_MODES = {'select_first', 'original'}
text_mode = 'select_first' if text_mode not in VALID_TEXT_MODES else text_mode
dataset = RefCoco(ann_file=..., data_prefix=..., split='train', text_mode=text_mode) Type guard
def is_valid_text_mode(mode: str) -> bool:
return mode in {'select_first', 'original'} Prevention
- Pin the exact supported text_mode strings for your installed mmdet version by checking mmdet/datasets/refcoco.py
- Treat config strings as an enum, not free text; validate against the known set at config parse time
When it happens
Trigger: Constructing RefCoco (or building its transform pipeline in a config) with text_mode set to anything other than 'select_first' or 'original' — e.g. 'random', 'last', a typo like 'orginal', or None.
Common situations: Porting configs from older mmdet versions or other referring-expression codebases where text_mode='random' existed; typos in config strings; assuming all modes listed in a paper are implemented.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- No sample in split "{self.split}".
- The type of frame_range must be int or list.
- results does not contain masks.
- {metric} is not in results
- metric must be a list or a str.
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/7554f65eb8377e04.
Report an issue: GitHub.