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



因此解决方案为:
将train.py代码中的内容
def train_model(
model,
device,
epochs: int = 8,
batch_size: int = 16,
learning_rate: float = 1e-5,
val_percent: float = 0.1,
save_checkpoint: bool = True,
img_scale: float = 0.5,
amp: bool = False,
weight_decay: float = 1e-8,
momentum: float = 0.999,
gradient_clipping: float = 1.0,
):
改为
def train_model(
model,
device,
epochs: int = 8,
batch_size: int = 16,
learning_rate: float = 0.0001,
val_percent: float = 0.1,
save_checkpoint: bool = True,
img_scale: float = 0.5,
amp: bool = False,
weight_decay: float = 1e-8,
momentum: float = 0.999,
gradient_clipping: float = 1.0,
):
learning_rate: float = 1e-5 ——>修改为——> learning_rate: float = 0.0001
再次尝试运行就可以正常输出得到正常的各项Dice值了
tips:一旦成功得到各项指标以后,再把学习率改回去,可能就无法复现之前的“趋近于0”的现象了。