当前位置:   article > 正文

Unet语义分割模型训练自定义过程中出现dice score趋近于0或者负值的解决方案(使用的仓库代码为——https://github.com/milesial/Pytorch-UNet)_validation dice score

validation dice score

使用仓库代码如下的时候:milesial/Pytorch-UNet: PyTorch implementation of the U-Net for image semantic segmentation with high quality images (github.com)icon-default.png?t=N7T8https://github.com/milesial/Pytorch-UNet发现dice值无论和validation Dice始终为负值和趋近于(无限接近于0)0,具体情况如下图所示。

学习率为 learning_rate: float = 1e-5
对应的Val Dice值几乎无限趋近于0

修改学习率以后,各项Dice值正常了

参考——Dice coefficient no change during training,is always very close to 0 · Issue #173 · milesial/Pytorch-UNet (github.com)icon-default.png?t=N7T8https://github.com/milesial/Pytorch-UNet/issues/173

因此解决方案为:

将train.py代码中的内容

  1. def train_model(
  2. model,
  3. device,
  4. epochs: int = 8,
  5. batch_size: int = 16,
  6. learning_rate: float = 1e-5,
  7. val_percent: float = 0.1,
  8. save_checkpoint: bool = True,
  9. img_scale: float = 0.5,
  10. amp: bool = False,
  11. weight_decay: float = 1e-8,
  12. momentum: float = 0.999,
  13. gradient_clipping: float = 1.0,
  14. ):

改为

  1. def train_model(
  2. model,
  3. device,
  4. epochs: int = 8,
  5. batch_size: int = 16,
  6. learning_rate: float = 0.0001,
  7. val_percent: float = 0.1,
  8. save_checkpoint: bool = True,
  9. img_scale: float = 0.5,
  10. amp: bool = False,
  11. weight_decay: float = 1e-8,
  12. momentum: float = 0.999,
  13. gradient_clipping: float = 1.0,
  14. ):

 learning_rate: float = 1e-5 ——>修改为——> learning_rate: float =  0.0001

再次尝试运行就可以正常输出得到正常的各项Dice值了

tips:一旦成功得到各项指标以后,再把学习率改回去,可能就无法复现之前的“趋近于0”的现象了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/98082
推荐阅读
相关标签
  

闽ICP备14008679号