分割模型
分割类别只有person,假设输入为3x512x512
1、BackBone
首先对输入下采样两次得到BSx3x128x128,作为主干网络HrNet18的输入,下采样3次,共四个分支,特征图大小分别为[128x128, 64x64, 32x32, 16x16],通道维度分别为[18, 36, 72, 144]:
2、Head
将下采样的三个分支上采样:双线性差值,和高分辨率的第一个分支在channel维度拼接,共270维,拼接后的输出为BSx270x128x128,然后使用卷积nn.Conv2d(270, 2)将通道数270变为类别数2,最后对特征图上采样到原图的尺寸512x512;
3、Loss
损失为交叉熵或者DiceLoss
交叉熵:先使用softmax将特征值变为概率分布的形式,然后通过y*logp计算交叉熵损失;
DiceLoss:其实就是F1Score: 2PR/(P+R);
4、Accuracy
对于输出BSx2x512x512,使用torch.topk(BSx2x512x512, k=1, dim=1返回最大值(BSx512x512)和对应的索引(BSx512x512),其中索引为0代表第一个特征图的值更大,该像素为背景,索引为1代表第二个特征图的值更大,该像素为前景;
使用索引和GT计算Accuracy;