Skip to content

DBNet: follow loss naming convention #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configs/det/dbnet/db++_r50_icdar15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_mobilenetv3_icdar15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r18_ctw1500.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r18_icdar15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r18_mlt2017.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r18_synthtext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ model:
adaptive: True

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r18_td500.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r18_totaltext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r50_ctw1500.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r50_icdar15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r50_mlt2017.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r50_synthtext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ model:
adaptive: True

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r50_td500.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
2 changes: 1 addition & 1 deletion configs/det/dbnet/db_r50_totaltext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand Down
4 changes: 2 additions & 2 deletions docs/cn/tutorials/training_detection_custom_dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand All @@ -234,7 +234,7 @@ optimizer:
momentum: 0.9
weight_decay: 1.0e-4
```
它使用 `SGD` 优化器(在 `mindocr/optim/optim.factory.py` 中)和 `polynomial_decay`(在 `mindocr/scheduler/scheduler_factory.py` 中)作为学习率调整策略。损失函数是 `L1BalancedCELoss`(在 `mindocr/losses/det_loss.py` 中),评估指标是 `DetMetric`(在 `mindocr/metrics/det_metrics.py` 中)。
它使用 `SGD` 优化器(在 `mindocr/optim/optim.factory.py` 中)和 `polynomial_decay`(在 `mindocr/scheduler/scheduler_factory.py` 中)作为学习率调整策略。损失函数是 `DBLoss`(在 `mindocr/losses/det_loss.py` 中),评估指标是 `DetMetric`(在 `mindocr/metrics/det_metrics.py` 中)。

## 3. 模型训练, 测试和推理

Expand Down
2 changes: 1 addition & 1 deletion docs/cn/tutorials/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

| 字段 | 用途 | 默认值 | 备注 |
| :---- | :---- | :---- | :---- |
| name | 损失函数类名 | - | 目前支持 L1BalancedCELoss, CTCLoss, AttentionLoss, PSEDiceLoss, EASTLoss and CrossEntropySmooth |
| name | 损失函数类名 | - | 目前支持 DBLoss, CTCLoss, AttentionLoss, PSEDiceLoss, EASTLoss and CrossEntropySmooth |
| pred_seq_len | 预测文本的长度 | 26 | 由网络架构决定 |
| max_label_len | 最长标签长度 | 25 | 数值应小于网络预测文本的长度 |
| batch_size | 单卡批量大小 | 32 | \ |
Expand Down
4 changes: 2 additions & 2 deletions docs/en/tutorials/training_detection_custom_dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ metric:
main_indicator: f-score

loss:
name: L1BalancedCELoss
name: DBLoss
eps: 1.0e-6
l1_scale: 10
bce_scale: 5
Expand All @@ -233,7 +233,7 @@ optimizer:
momentum: 0.9
weight_decay: 1.0e-4
```
It uses `SGD` optimizer (in `mindocr/optim/optim.factory.py`) and `polynomial_decay` (in `mindocr/scheduler/scheduler_factory.py`) as the learning scheduler. The loss function is `L1BalancedCELoss` (in `mindocr/losses/det_loss.py`) and the evaluation metric is `DetMetric` ( in `mindocr/metrics/det_metrics.py`).
It uses `SGD` optimizer (in `mindocr/optim/optim.factory.py`) and `polynomial_decay` (in `mindocr/scheduler/scheduler_factory.py`) as the learning scheduler. The loss function is `DBLoss` (in `mindocr/losses/det_loss.py`) and the evaluation metric is `DetMetric` ( in `mindocr/metrics/det_metrics.py`).


## 3. Model Training, Evaluation, and Inference
Expand Down
2 changes: 1 addition & 1 deletion docs/en/tutorials/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Please see the code in [mindocr/losses](../../../mindocr/losses)

| Parameter | Description | Default | Remarks |
| :---- | :---- | :---- | :---- |
| name | loss function name | - | Currently supports L1BalancedCELoss, CTCLoss, AttentionLoss, PSEDiceLoss, EASTLoss and CrossEntropySmooth |
| name | loss function name | - | Currently supports DBLoss, CTCLoss, AttentionLoss, PSEDiceLoss, EASTLoss and CrossEntropySmooth |
| pred_seq_len | length of predicted text | 26 | Determined by network architecture |
| max_label_len | The longest label length | 25 | The value is less than the length of the text predicted by the network |
| batch_size | single card batch size | 32 | \ |
Expand Down
4 changes: 2 additions & 2 deletions mindocr/losses/builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__all__ = ["build_loss"]

supported_losses = [
"L1BalancedCELoss",
"DBLoss",
"CTCLoss",
"AttentionLoss",
"PSEDiceLoss",
Expand All @@ -11,7 +11,7 @@
]

from .cls_loss import CrossEntropySmooth
from .det_loss import EASTLoss, FCELoss, L1BalancedCELoss, PSEDiceLoss
from .det_loss import DBLoss, EASTLoss, FCELoss, PSEDiceLoss
from .rec_loss import AttentionLoss, CTCLoss


Expand Down
5 changes: 2 additions & 3 deletions mindocr/losses/det_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import mindspore.numpy as mnp
from mindspore import Tensor, nn, ops

__all__ = ["L1BalancedCELoss", "PSEDiceLoss", "EASTLoss", "FCELoss"]
__all__ = ["DBLoss", "PSEDiceLoss", "EASTLoss", "FCELoss"]
_logger = logging.getLogger(__name__)


class L1BalancedCELoss(nn.LossBase):
class DBLoss(nn.LossBase):
"""
Apply Balanced CrossEntropy Loss on `binary`, MaskL1Loss on `thresh`, DiceLoss on `thresh_binary` and return
overall weighted loss.
Expand Down