|
63 | 63 | parser.add_argument('--cosface', action='store_true', help='use CosFace loss' )
|
64 | 64 | parser.add_argument('--contrast', action='store_true', help='use contrast loss' )
|
65 | 65 | parser.add_argument('--instance', action='store_true', help='use instance loss' )
|
| 66 | +parser.add_argument('--ins_gamma', default=32, type=int, help='gamma for instance loss') |
66 | 67 | parser.add_argument('--triplet', action='store_true', help='use triplet loss' )
|
67 | 68 | parser.add_argument('--lifted', action='store_true', help='use lifted loss' )
|
68 | 69 | parser.add_argument('--sphere', action='store_true', help='use sphere loss' )
|
@@ -216,7 +217,7 @@ def train_model(model, criterion, optimizer, scheduler, num_epochs=25):
|
216 | 217 | if opt.contrast:
|
217 | 218 | criterion_contrast = losses.ContrastiveLoss(pos_margin=0, neg_margin=1)
|
218 | 219 | if opt.instance:
|
219 |
| - criterion_instance = InstanceLoss(gamma=8) |
| 220 | + criterion_instance = InstanceLoss(gamma = opt.ins_gamma) |
220 | 221 | if opt.sphere:
|
221 | 222 | criterion_sphere = losses.SphereFaceLoss(num_classes=opt.nclasses, embedding_size=512, margin=4)
|
222 | 223 | for epoch in range(num_epochs):
|
@@ -283,7 +284,7 @@ def train_model(model, criterion, optimizer, scheduler, num_epochs=25):
|
283 | 284 | if opt.contrast:
|
284 | 285 | loss += criterion_contrast(ff, labels) #/now_batch_size
|
285 | 286 | if opt.instance:
|
286 |
| - loss += criterion_instance(ff, labels) |
| 287 | + loss += criterion_instance(ff, labels) /now_batch_size |
287 | 288 | if opt.sphere:
|
288 | 289 | loss += criterion_sphere(ff, labels)/now_batch_size
|
289 | 290 | elif opt.PCB: # PCB
|
|
0 commit comments