pytorch-adacos icon indicating copy to clipboard operation
pytorch-adacos copied to clipboard

No optimizer for metric_fc?

Open fyang93 opened this issue 5 years ago • 2 comments

As far as I know, the centers (self.W) in losses should be updated during training. To do that, it requires using optimizers on both the model and the metric_fc (e.g. ArcFace). However, I did not find any optimizer set on metric_fc in your code so technically the centers won't be updated anyway... Is it supposed to be like that?

fyang93 avatar Nov 14 '19 21:11 fyang93

Very good catch :) Then only backbone is learned and in classification layer just random weight stay for all training. Author should change this implementation, guided by your explenation.

melgor avatar Mar 16 '20 07:03 melgor

what you can do is inside your model class define let's say you are using ArcFace. define it as follows

class Model:

   def __init__(self , args):
         #Define your model here
        self.fc = ArcFace(num_features , n_classes)

 def forward(self , inp , targets):
        feature = self.model(inp)
        arc_op = self.fc(feature , targets)
        return arc_op

when you define optimizer opt = SGD(model.parameters() , 1e-3)

I think this should work, since the ArcFace Repo you mentioned gets only features(in that repo 512 dimensional embedding) from the Resnet Model and the passes it to ArcFace module. Hence I think defining model as above should in theory work.

Atharva-Phatak avatar Jan 18 '21 10:01 Atharva-Phatak