Closed csyuhao closed 3 years ago
Using directly the embedding of the pretrained model may be better. The model lookalikes as the following:
`class Arcface(nn.Module):
def __init__(self, embedding_size=512, classnum=28):
super(Arcface, self).__init__()
self.embedding_size = embedding_size
self.relu = nn.ReLU(inplace=True)
self.fc_1 = nn.Linear(embedding_size, 2048)
self.fc = nn.Linear(2048, classnum)
def forward(self, input):
global_feat = self.fc_1(input)
global_feat = self.relu(global_feat)
global_feat = F.dropout(global_feat, p=0.2)
logits = self.fc(global_feat)
return logits`
@yuhaoooo Hi,如果想要微调模型,需要怎么弄啊?不太知道怎么弄,想请教下你。非常感谢~
一般来说,人脸识别模型是由特征提取器和分类头组成。特征提取器就是在大的训练数据集上,利用ArcFace、CosFace等特殊的损失函数训练的模型。而分类头是由多层感知机、SVM、或者聚类算法实现的。在微调的时候,我们一般不会重新训练特征提取器。除非你有一个更大的本地数据集,否则我们只对分类头进行训练。
@yuhaoooo 对,是这样,但是我对pytorch不熟悉,不知道代码需要改哪些地方怎么改,方便提供下你的这部分代码吗?谢谢~
你是说这个repo里面的代码?这个repo我没细看,我推荐你看这个Face_Pytorch。在train_softmax.py把#L109改成
optimizer_classi = optim.SGD([
{'params': margin.parameters(), 'weight_decay': 5e-4}
], lr=0.1, momentum=0.9, nesterov=True)
再把下边的net.train()
改成net.eval()
就行了。
@yuhaoooo 非常感谢!!!!
Hi @yuhaoooo , I hope you are having nice results, I am wondering if you finally found a way to tune with your dataset.
Can you share with the community your code?
一般来说,人脸识别模型是由特征提取器和分类头组成。特征提取器就是在大的训练数据集上,利用ArcFace、CosFace等特殊的损失函数训练的模型。而分类头是由多层感知机、SVM、或者聚类算法实现的。在微调的时候,我们一般不会重新训练特征提取器。除非你有一个更大的本地数据集,否则我们只对分类头进行训练。
那训练完成后只能对训练集中的人利用分类来进行识别嘛? 数据集之外的人是不是就没法识别了
Thanks @TreB1eN for the great work! I was trying to fine-tune on a small dataset by the pretraind model IR-SE50. In this process, I do not train the embedding model, but add the
nn.Linear
layer to dosoftmax
classification.There are the related code. The input of
nn.Linear
is embeddings before normed.The
forward
part ofBackbone
is also changed as follows:However, in the training process, the loss is downing very slow. The
lr
is 1e-3, and the optimizer isAdam
.Could you give me some advice, or point out where my mistakes are?