PaddleSeg icon indicating copy to clipboard operation
PaddleSeg copied to clipboard

Target 254 is out of upper bound

Open pughua opened this issue 2 years ago • 6 comments

Thanks for your issue. To help us solve the issue better, please provide following information:

  1. PaddleSeg version:2.7
  2. PaddlePaddle version: 2.3.2
  3. Operation system: Windows
  4. Python version: 3.9

训练时出现以下问题,该如何处理: ` D:\AI\ZhongyiAISolution1\Paddlepaddle2Application\tools\PaddleSeg-release-2.7>python tools/train.py --config configs/quick_start/config_tongue_set.yml --do_eval --use_vdl --save_interval 500 --save_dir output 2022-12-08 17:46:08 [INFO] ------------Environment Information------------- platform: Windows-10-10.0.19045-SP0 Python: 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] Paddle compiled with cuda: False GCC: gcc (x86_64-posix-sjlj-rev0, Built by MinGW-W64 project) 5.4.0 PaddleSeg: 2.7.0 PaddlePaddle: 2.3.2 OpenCV: 4.6.0

2022-12-08 17:46:08 [INFO] ---------------Config Information--------------- batch_size: 4 iters: 1000 loss: coef:

  • 1
  • 1
  • 1 types:
  • ignore_index: 255 type: CrossEntropyLoss lr_scheduler: end_lr: 0 learning_rate: 0.01 power: 0.9 type: PolynomialDecay model: backbone: in_channels: 3 pretrained: https://bj.bcebos.com/paddleseg/dygraph/PP_STDCNet2.tar.gz type: STDC2 num_classes: 3 type: PPLiteSeg optimizer: momentum: 0.9 type: sgd weight_decay: 4.0e-05 train_dataset: dataset_root: data/work_tongue_data img_channels: 3 mode: train num_classes: 3 train_path: data/work_tongue_data/train_list.txt transforms:
  • max_scale_factor: 2.0 min_scale_factor: 0.5 scale_step_size: 0.25 type: ResizeStepScaling
  • crop_size:
    • 512
    • 512 type: RandomPaddingCrop
  • type: RandomHorizontalFlip
  • brightness_range: 0.5 contrast_range: 0.5 saturation_range: 0.5 type: RandomDistort
  • type: Normalize type: Dataset val_dataset: dataset_root: data/work_tongue_data img_channels: 3 mode: val num_classes: 3 transforms:
  • type: Normalize type: Dataset val_path: data/work_tongue_data/val_list.txt

2022-12-08 17:46:10 [INFO] Loading pretrained model from https://bj.bcebos.com/paddleseg/dygraph/PP_STDCNet2.tar.gz 2022-12-08 17:46:10 [INFO] There are 265/265 variables loaded into STDCNet. C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\paddle\nn\layer\norm.py:653: UserWarning: When training, we now always track global mean and variance. warnings.warn( Traceback (most recent call last): File "D:\AI\ZhongyiAISolution1\Paddlepaddle2Application\tools\PaddleSeg-release-2.7\tools\train.py", line 259, in main(args) File "D:\AI\ZhongyiAISolution1\Paddlepaddle2Application\tools\PaddleSeg-release-2.7\tools\train.py", line 235, in main train( File "C:\Users\lemonnc\AppData\Roaming\Python\Python39\site-packages\paddleseg\core\train.py", line 207, in train loss_list = loss_computation( File "C:\Users\lemonnc\AppData\Roaming\Python\Python39\site-packages\paddleseg\core\train.py", line 55, in loss_computation loss_list.append(coef_i * loss_i(logits, labels)) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\paddle\fluid\dygraph\layers.py", line 930, in call return self._dygraph_call_func(*inputs, **kwargs) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\paddle\fluid\dygraph\layers.py", line 915, in _dygraph_call_func outputs = self.forward(*inputs, **kwargs) File "C:\Users\lemonnc\AppData\Roaming\Python\Python39\site-packages\paddleseg\models\losses\cross_entropy_loss.py", line 81, in forward loss = F.cross_entropy( File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\paddle\nn\functional\loss.py", line 1722, in cross_entropy raise ValueError("Target {} is out of upper bound.".format( ValueError: Target 254 is out of upper bound. `

pughua avatar Dec 08 '22 09:12 pughua

请确认使用的数据集标签中是否带有254这一数值。指定的类别数(num_classes)是3,因此254是一个非法类别。

Bobholamovic avatar Dec 08 '22 11:12 Bobholamovic

用EISeg的伪彩色标注图(_pseudo图)就不行,用EISeg灰度标注图才行

pughua avatar Dec 09 '22 06:12 pughua

用EISeg的伪彩色标注图(_pseudo图)就不行,用EISeg灰度标注图才行

可以尝试一下用PIL.Image.open读入伪彩色标注图后取值是否为从0开始的连续数值,例如:

import numpy as np
from PIL import Image

im = np.asarray(Image.open({伪彩色标注图路径}))
print(np.unique(im))

在图像中存在3个类别时,输出应该是[0, 1, 2]

若上述条件不满足,则说明伪彩色标注图存在问题,不能直接用于模型训练。

Bobholamovic avatar Dec 09 '22 07:12 Bobholamovic

_pseudo图输出结果是[ 0, 53, 119, 181]

pughua avatar Feb 06 '23 08:02 pughua

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Apr 07 '23 17:04 github-actions[bot]

需要修改标签为0,1,2....的连续数字

shiyutang avatar Feb 27 '24 12:02 shiyutang