{"record":{"id":"ec178980cf19e6f4","repo":"PaddlePaddle/PaddleOCR","slug":"dbloss-unrecognized-main-loss-type","errorCode":null,"errorMessage":"[DBLoss]: Unrecognized main loss type!","messagePattern":"\\[DBLoss\\]: Unrecognized main loss type!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ppocr/losses/det_db_loss.py","lineNumber":74,"sourceCode":"        self.l1_loss = MaskL1Loss(eps=eps)\n        if main_loss_type == \"DiceFocalLoss\":\n            self.bce_loss = DiceFocalLoss(\n                dice_weight=dice_weight,\n                focal_weight=focal_weight,\n                focal_alpha=focal_alpha,\n                focal_gamma=focal_gamma,\n                eps=eps,\n            )\n            self.dice_loss = self.bce_loss\n        elif main_loss_type == \"DiceLoss\":\n            self.bce_loss = BalanceLoss(\n                balance_loss=balance_loss,\n                main_loss_type=main_loss_type,\n                negative_ratio=ohem_ratio,\n            )\n            self.dice_loss = DiceLoss(eps=eps)\n        else:\n            raise Exception(\"[DBLoss]: Unrecognized main loss type!\")\n        self.aux_weight_p4 = aux_weight_p4\n        self.aux_weight_p3 = aux_weight_p3\n        self.aux_weight_p2 = aux_weight_p2\n\n    def forward(self, predicts, labels):\n        predict_maps = predicts[\"maps\"]\n        (\n            label_threshold_map,\n            label_threshold_mask,\n            label_shrink_map,\n            label_shrink_mask,\n        ) = labels[1:]\n        shrink_maps = predict_maps[:, 0, :, :]\n        threshold_maps = predict_maps[:, 1, :, :]\n        binary_maps = predict_maps[:, 2, :, :]\n\n        loss_shrink_maps = self.bce_loss(\n            shrink_maps, label_shrink_map, label_shrink_mask","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/losses/det_db_loss.py#L56-L92","documentation":"DBLoss.__init__ branches on main_loss_type and only wires up 'BCELoss' (bce_loss path with BalanceLoss) and 'DiceLoss' (BalanceLoss + DiceLoss). Even though BalanceLoss itself supports five types, DBLoss as a whole only accepts these two, and anything else raises Exception('[DBLoss]: Unrecognized main loss type!').","triggerScenarios":"Constructing DBLoss(main_loss_type='MaskL1Loss') or 'CrossEntropy' — values legal for BalanceLoss but not for DBLoss; typically via a det_db config YAML.","commonSituations":"Copying a BalanceLoss-supported type into a DB config, or upgrading configs from another detection model where those types were valid, then hitting a confusing error because the inner class accepts them.","solutions":["Set main_loss_type to 'BCELoss' or 'DiceLoss' in the DBLoss config","Verify you are editing the Loss section of the actual det model config being loaded (not a base config that is overridden)"],"exampleFix":"# before (config yaml)\nLoss:\n  name: DBLoss\n  main_loss_type: MaskL1Loss\n\n# after\nLoss:\n  name: DBLoss\n  main_loss_type: DiceLoss","handlingStrategy":"validation","validationCode":"DB_LOSS_TYPES = {'BCELoss', 'DiceLoss'}\nassert main_loss_type in DB_LOSS_TYPES, f'DBLoss supports only {DB_LOSS_TYPES}, got {main_loss_type!r}'","typeGuard":"def is_db_loss_type(t: str) -> bool:\n    return t in {'BCELoss', 'DiceLoss'}","tryCatchPattern":null,"preventionTips":["Note the narrower set vs BalanceLoss: DBLoss accepts only BCELoss/DiceLoss","Assert the loss config the moment it is parsed so the failure points at the YAML, not at model build","Run a 1-iteration smoke train on config changes"],"tags":["config","loss","db","text-detection","enum-value"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}