open-mmlab/mmdetection · error · RuntimeError

transformers is not installed, please install it by: pip ins

Error message

transformers is not installed, please install it by: pip install transformers.

What it means

RandomSamplingNegativeText in text_transformers.py builds text prompts for grounding models (GLIP/Grounding DINO style) and needs HuggingFace transformers' AutoTokenizer. If transformers failed to import at module load, __init__ raises RuntimeError telling you to install it.

Source

Thrown at mmdet/datasets/transforms/text_transformers.py:106

        # if index != len(label_list) - 1:
        #     pheso_caption += '. '
        pheso_caption += '. '

    return label_to_positions, pheso_caption, label_remap_dict


@TRANSFORMS.register_module()
class RandomSamplingNegPos(BaseTransform):

    def __init__(self,
                 tokenizer_name,
                 num_sample_negative=85,
                 max_tokens=256,
                 full_sampling_prob=0.5,
                 label_map_file=None):
        if AutoTokenizer is None:
            raise RuntimeError(
                'transformers is not installed, please install it by: '
                'pip install transformers.')

        self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
        self.num_sample_negative = num_sample_negative
        self.full_sampling_prob = full_sampling_prob
        self.max_tokens = max_tokens
        self.label_map = None
        if label_map_file:
            with open(label_map_file, 'r') as file:
                self.label_map = json.load(file)

    def transform(self, results: dict) -> dict:
        if 'phrases' in results:
            return self.vg_aug(results)
        else:
            return self.od_aug(results)

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. pip install transformers
  2. Verify python -c "from transformers import AutoTokenizer" works and matches the model needed (e.g. bert-base-uncased is downloadable)
  3. If offline, set HF_HOME/transformers cache or TRANSFORMERS_OFFLINE=1 after pre-downloading the tokenizer
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
if importlib.util.find_spec('transformers') is None:
    raise SystemExit('pip install transformers')

Prevention

When it happens

Trigger: Constructing dict(type='RandomSamplingNegativeText', tokenizer_name='bert-base-uncased', ...) when the optional `transformers` package is absent, so AutoTokenizer is None at module import time.

Common situations: Running grounding-detection configs (GLIP, Grounding DINO) in a minimal mmdet install that skipped extra text dependencies; installing mmdet via pip without extras; transformers present but its import crashed at module load leaving AutoTokenizer None.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/60480c1be6de63e0. Report an issue: GitHub.