{"record":{"id":"494a4a6ddcc3b9b1","repo":"open-mmlab/mmdetection","slug":"please-run-pip-install-scipy-to-install-scipy-fi","errorCode":null,"errorMessage":"Please run \"pip install scipy\" to install scipy first.","messagePattern":"Please run \"pip install scipy\" to install scipy first\\.","errorType":"error_code","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"mmdet/models/task_modules/assigners/hungarian_assigner.py","lineNumber":128,"sourceCode":"                num_gts=num_gts,\n                gt_inds=assigned_gt_inds,\n                max_overlaps=None,\n                labels=assigned_labels)\n\n        # 2. compute weighted cost\n        cost_list = []\n        for match_cost in self.match_costs:\n            cost = match_cost(\n                pred_instances=pred_instances,\n                gt_instances=gt_instances,\n                img_meta=img_meta)\n            cost_list.append(cost)\n        cost = torch.stack(cost_list).sum(dim=0)\n\n        # 3. do Hungarian matching on CPU using linear_sum_assignment\n        cost = cost.detach().cpu()\n        if linear_sum_assignment is None:\n            raise ImportError('Please run \"pip install scipy\" '\n                              'to install scipy first.')\n\n        matched_row_inds, matched_col_inds = linear_sum_assignment(cost)\n        matched_row_inds = torch.from_numpy(matched_row_inds).to(device)\n        matched_col_inds = torch.from_numpy(matched_col_inds).to(device)\n\n        # 4. assign backgrounds and foregrounds\n        # assign all indices to backgrounds first\n        assigned_gt_inds[:] = 0\n        # assign foregrounds based on matching results\n        assigned_gt_inds[matched_row_inds] = matched_col_inds + 1\n        assigned_labels[matched_row_inds] = gt_labels[matched_col_inds]\n        return AssignResult(\n            num_gts=num_gts,\n            gt_inds=assigned_gt_inds,\n            max_overlaps=None,\n            labels=assigned_labels)\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/task_modules/assigners/hungarian_assigner.py#L110-L146","documentation":"HungarianAssigner uses scipy.optimize.linear_sum_assignment for optimal bipartite matching; if scipy failed to import, assign() raises ImportError at matching time (not construction time), telling you to pip install scipy.","triggerScenarios":"Building a DETR/Deformable-DETR/DINO-style model (hungarian assigner) in an environment without scipy, then running training or loss computation.","commonSituations":"Minimal torch-only environments; scipy broken by a numpy version conflict so the guarded import returns None.","solutions":["pip install scipy","If numpy/scipy ABI conflicts occur, upgrade both: pip install -U numpy scipy","Verify: python -c \"from scipy.optimize import linear_sum_assignment\""],"exampleFix":"# before\nImportError during HungarianAssigner.assign\n# after\npip install scipy  # training runs","handlingStrategy":"validation","validationCode":"try:\n    from scipy.optimize import linear_sum_assignment  # noqa\n    ok = True\nexcept ImportError:\n    ok = False\nassert ok, 'scipy required for HungarianAssigner'","typeGuard":null,"tryCatchPattern":"try:\n    model.train()\nexcept ImportError as e:\n    raise SystemExit('Missing scipy: pip install scipy') from e","preventionTips":["Add scipy to training environment requirements","Smoke-test one training step before long runs to surface import-time gaps"],"tags":["mmdetection","detr","hungarian-assigner","scipy","missing-dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}