对于《Self-Cure Net抑制大规模人脸情绪识别的不确定性》论文及代码阅读总结
论文核心概括
不确定的面部表情和低质量的图像质量和图片注释的不准确给面部识别的神经网络带来了巨大挑战,文章通过
1)注意力机制和
2)对样本的重新排名机制
使得该网络可以有效地抑制不确定性并防止深度网络过度拟合不确定的面部图像
核心内容
一、注意力机制
def forward(self, x):
x = self.features(x)
if self.drop_rate > 0:
x = nn.Dropout(self.drop_rate)(x)
x = x.view(x.size(0), -1)
attention_weights = self.alpha(x)
out = attention_weights * self.fc(x)
return attention_weights, out
通过对样本全连接层加入注意力因子(attention_weights)来确定某一样本的真实准确性,数值高代表样本表现好,准确度高,在训练时“发挥的作用”大,反之则样本表现差(由上述不确定因素引起),准确度底,训练时不理想。通过该因子(attention_weights * self.fc(x)),神经网络将注意力集中在实际效果好更有效的样本上,以此提高训练的准确度。
加权交叉熵(WCE-Loss)作为损失函数(个人理解为用因为预测的是一个概率分布,所以要用加权交叉熵来作为评判标准)
二、对样本的重新排名机制
# Relabel samples
if i >= args.relabel_epoch:
sm = torch.softmax(outputs, dim = 1)
Pmax, predicted_labels = torch.max(sm, 1) # predictions 最大可能性的概率+标签
Pgt = torch.gather(sm, 1, targets.view(-1,1)).squeeze() # retrieve predicted probabilities of targets
true_or_false = Pmax - Pgt > margin_2
update_idx = true_or_false.nonzero().squeeze() # get samples' index in this mini-batch where (Pmax - Pgt > margin_2)
label_idx = indexes[update_idx] # get samples' index in train_loader
relabels = predicted_labels[update_idx] # predictions where (Pmax - Pgt > margin_2)
train_loader.dataset.label[label_idx.cpu().numpy()] = relabels.cpu().numpy() # relabel samples in train_loader
样本的重新排名依赖训练时预测值和实际值的对比差值(Pmax - Pgt),当某一个样本的对比差值大于超参数margin_2时,则将样本的标签修改为实际值,并传入训练集中,进一步减少数据集人为的标注的失误,凸显有些样本的重要之处。
三、ResNet18
def __init__(self, pretrained = True, num_classes = 7, drop_rate = 0):
super(Res18Feature, self).__init__()
self.drop_rate = drop_rate
resnet = models.resnet18(pretrained)
# self.feature = nn.Sequential(*list(resnet.children())[:-2]) # before avgpool
self.features = nn.Sequential( *list(resnet.children())[:-1]) # after avgpool 512x1
fc_in_dim = list(resnet.children())[-1].in_features # original fc layer's in dimention 512
self.fc = nn.Linear(fc_in_dim, num_classes) # new fc layer 512x7
self.alpha = nn.Sequential(nn.Linear(fc_in_dim, 1),nn.Sigmoid())
网络采用经典resnet18网络预训练,加深网络,提高训练速度。
总结
本文提出了一种自治愈网络(SCN),以抑制面部表情数据的不确定性,提高网络的鲁棒性和对结果的准确性。同时代码结构相对来说比较清晰,代码和论文同时对照,对于刚入门深度学习的人来说,能够加强对网络和参数,以及对样本的输入与处理的理解
参考资料
https://blog.csdn.net/acceptedday/article/details/104884235
参考代码 https://github.com/kaiwang960112/Self-Cure-Network
(数据集缺省)