From a4e4b0a0a17b38f9c900734b992d1ebfc416775b Mon Sep 17 00:00:00 2001 From: MengzhangLI Date: Wed, 30 Mar 2022 13:58:17 +0800 Subject: [PATCH] fix --- docs/en/tutorials/training_tricks.md | 2 +- docs/zh_cn/tutorials/training_tricks.md | 2 +- mmseg/models/losses/cross_entropy_loss.py | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/en/tutorials/training_tricks.md b/docs/en/tutorials/training_tricks.md index 5256583167..6ff2c4249d 100644 --- a/docs/en/tutorials/training_tricks.md +++ b/docs/en/tutorials/training_tricks.md @@ -73,7 +73,7 @@ Note: If you want this loss item to be included into the backward graph, `loss_` In default setting, `avg_non_ignore=False` which means each pixel counts for loss calculation although some of them belong to ignore-index labels. -For loss calculation, we support ignore index of certain label by `avg_non_ignore` and `ignore_index`. In this way, the average loss would only be calculated in non-ignored labels which may achieve better performance. Here is an example config of training `unet` on `Cityscapes` dataset: in loss calculation it would ignore label 0 which is background and loss average is only calculated on non-ignore labels: +For loss calculation, we support ignore index of certain label by `avg_non_ignore` and `ignore_index`. In this way, the average loss would only be calculated in non-ignored labels which may achieve better performance, and here is the [reference](https://github.com/open-mmlab/mmsegmentation/pull/1409). Here is an example config of training `unet` on `Cityscapes` dataset: in loss calculation it would ignore label 0 which is background and loss average is only calculated on non-ignore labels: ```python _base_ = './fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes.py' diff --git a/docs/zh_cn/tutorials/training_tricks.md b/docs/zh_cn/tutorials/training_tricks.md index ddd58f6619..2efbdf177c 100644 --- a/docs/zh_cn/tutorials/training_tricks.md +++ b/docs/zh_cn/tutorials/training_tricks.md @@ -73,7 +73,7 @@ model = dict( 默认设置 `avg_non_ignore=False`, 即每个像素都用来计算损失函数。尽管其中的一些像素属于需要被忽略的类别。 -对于训练时损失函数的计算,我们目前支持使用 `avg_non_ignore` 和 `ignore_index` 来忽略 label 特定的类别。 这样损失函数将只在非忽略类别像素中求平均值,会获得更好的表现。以 `unet` 使用 `Cityscapes` 数据集训练为例, +对于训练时损失函数的计算,我们目前支持使用 `avg_non_ignore` 和 `ignore_index` 来忽略 label 特定的类别。 这样损失函数将只在非忽略类别像素中求平均值,会获得更好的表现。这里是[相关 PR](https://github.com/open-mmlab/mmsegmentation/pull/1409)。以 `unet` 使用 `Cityscapes` 数据集训练为例, 在计算损失函数时,忽略 label 为0的背景,并且仅在不被忽略的像素上计算均值。配置文件写为: ```python diff --git a/mmseg/models/losses/cross_entropy_loss.py b/mmseg/models/losses/cross_entropy_loss.py index 5f781e0396..7c2158f832 100644 --- a/mmseg/models/losses/cross_entropy_loss.py +++ b/mmseg/models/losses/cross_entropy_loss.py @@ -107,8 +107,7 @@ def binary_cross_entropy(pred, avg_factor (int, optional): Average factor that is used to average the loss. Defaults to None. class_weight (list[float], optional): The weight for each class. - ignore_index (int): The label index to be ignored. - Default: -100. + ignore_index (int): The label index to be ignored. Default: -100. avg_non_ignore (bool): The flag decides to whether the loss is only averaged over non-ignored targets. Default: False. `New in version 0.23.0.`