{"record":{"id":"60480c1be6de63e0","repo":"open-mmlab/mmdetection","slug":"transformers-is-not-installed-please-install-it-b","errorCode":null,"errorMessage":"transformers is not installed, please install it by: pip install transformers.","messagePattern":"transformers is not installed, please install it by: pip install transformers\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"mmdet/datasets/transforms/text_transformers.py","lineNumber":106,"sourceCode":"\n        # if index != len(label_list) - 1:\n        #     pheso_caption += '. '\n        pheso_caption += '. '\n\n    return label_to_positions, pheso_caption, label_remap_dict\n\n\n@TRANSFORMS.register_module()\nclass RandomSamplingNegPos(BaseTransform):\n\n    def __init__(self,\n                 tokenizer_name,\n                 num_sample_negative=85,\n                 max_tokens=256,\n                 full_sampling_prob=0.5,\n                 label_map_file=None):\n        if AutoTokenizer is None:\n            raise RuntimeError(\n                'transformers is not installed, please install it by: '\n                'pip install transformers.')\n\n        self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)\n        self.num_sample_negative = num_sample_negative\n        self.full_sampling_prob = full_sampling_prob\n        self.max_tokens = max_tokens\n        self.label_map = None\n        if label_map_file:\n            with open(label_map_file, 'r') as file:\n                self.label_map = json.load(file)\n\n    def transform(self, results: dict) -> dict:\n        if 'phrases' in results:\n            return self.vg_aug(results)\n        else:\n            return self.od_aug(results)\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/datasets/transforms/text_transformers.py#L88-L124","documentation":"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.","triggerScenarios":"Constructing dict(type='RandomSamplingNegativeText', tokenizer_name='bert-base-uncased', ...) when the optional `transformers` package is absent, so AutoTokenizer is None at module import time.","commonSituations":"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.","solutions":["pip install transformers","Verify python -c \"from transformers import AutoTokenizer\" works and matches the model needed (e.g. bert-base-uncased is downloadable)","If offline, set HF_HOME/transformers cache or TRANSFORMERS_OFFLINE=1 after pre-downloading the tokenizer"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec('transformers') is None:\n    raise SystemExit('pip install transformers')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-download tokenizers (bert-base-uncased etc.) once and cache with HF_HOME set","Install grounding-model extras whenever running GLIP/Grounding DINO configs"],"tags":["mmdetection","transformers","huggingface","grounding-detection","missing-dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}