{"record":{"id":"1948b3188442b18d","repo":"open-mmlab/mmdetection","slug":"since-cross-entropy-is-not-set-the-num-classes-wi","errorCode":null,"errorMessage":"Since cross entropy is not set, the num_classes will be ignored.","messagePattern":"Since cross entropy is not set, the num_classes will be ignored\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/models/reid/linear_reid_head.py","lineNumber":73,"sourceCode":"                 topk: Union[int, Tuple[int]] = (1, ),\n                 init_cfg: Union[dict, List[dict]] = dict(\n                     type='Normal', layer='Linear', mean=0, std=0.01, bias=0)):\n        if mmpretrain is None:\n            raise RuntimeError('Please run \"pip install openmim\" and '\n                               'run \"mim install mmpretrain\" to '\n                               'install mmpretrain first.')\n        super(LinearReIDHead, self).__init__(init_cfg=init_cfg)\n\n        assert isinstance(topk, (int, tuple))\n        if isinstance(topk, int):\n            topk = (topk, )\n        for _topk in topk:\n            assert _topk > 0, 'Top-k should be larger than 0'\n        self.topk = topk\n\n        if loss_cls is None:\n            if isinstance(num_classes, int):\n                warnings.warn('Since cross entropy is not set, '\n                              'the num_classes will be ignored.')\n            if loss_triplet is None:\n                raise ValueError('Please choose at least one loss in '\n                                 'triplet loss and cross entropy loss.')\n        elif not isinstance(num_classes, int):\n            raise TypeError('The num_classes must be a current number, '\n                            'if there is cross entropy loss.')\n        self.loss_cls = MODELS.build(loss_cls) if loss_cls else None\n        self.loss_triplet = MODELS.build(loss_triplet) \\\n            if loss_triplet else None\n\n        self.num_fcs = num_fcs\n        self.in_channels = in_channels\n        self.fc_channels = fc_channels\n        self.out_channels = out_channels\n        self.norm_cfg = norm_cfg\n        self.act_cfg = act_cfg\n        self.num_classes = num_classes","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/reid/linear_reid_head.py#L55-L91","documentation":"Warning from LinearReIDHead.__init__: when loss_cls is None (no cross-entropy head), any integer num_classes passed in the config is meaningless and is ignored. The head needs at least one of loss_triplet or loss_cls; with only triplet loss there are no class logits, so num_classes plays no role.","triggerScenarios":"Configuring a ReID head with loss_cls=None (or omitted) while still supplying num_classes=751 (or any int). Only triplet loss is used, so num_classes is dead config.","commonSituations":"Building triplet-only person-ReID models (e.g., on Market-1501 style datasets) and leaving num_classes from a CE-based template in the config.","solutions":["Remove num_classes from the head config when loss_cls is None","Or set loss_cls=dict(type='CrossEntropyLoss', ...) if classification is actually wanted","Keep at least one of loss_triplet / loss_cls to avoid the companion ValueError"],"exampleFix":"# before\nnum_classes=751, loss_cls=None, loss_triplet=dict(type='TripletLoss')\n# after\nloss_triplet=dict(type='TripletLoss')  # num_classes removed","handlingStrategy":"validation","validationCode":"if reid_head_cfg.get('loss_cls') is None:\n    assert 'num_classes' not in reid_head_cfg, 'num_classes ignored when loss_cls is None'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep head configs minimal: only pass args the chosen losses consume","Add a config lint step for ReID heads"],"tags":["mmdet","reid","config","unused-argument"],"backgroundTag":"unused-config-argument","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}