三通道 one-hot 分割标签转像素类别编号,解决 only batches of spatial targets 报错

这个报错的根本原因是 PyTorch 的 CrossEntropyLoss 做多类语义分割时,要求标签 target 是 3 维张量[batch, H, W]、存像素类别