You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ifparams.jigsaw:
acc, acc_jigsaw=model.test_loop( val_loader)
writer.add_scalar('val/acc', acc, epoch)
writer.add_scalar('val/acc_jigsaw', acc_jigsaw, epoch)
elifparams.rotation:
acc, acc_rotation=model.test_loop( val_loader)
writer.add_scalar('val/acc', acc, epoch)
writer.add_scalar('val/acc_rotation', acc_rotation, epoch)
else:
acc=model.test_loop( val_loader)
writer.add_scalar('val/acc', acc, epoch)
print("a epoch test process cost{}s".format(time.time() -start_test_time))
ifacc>max_acc : #for baseline and baseline++, we don't use validation here so we let acc = -1print("best model! save...")
max_acc=accoutfile=os.path.join(params.checkpoint_dir, 'best_model.tar')
torch.save({'epoch':epoch, 'state':model.state_dict()}, outfile)
if ((epoch+1) %params.save_freq==0) or (epoch==stop_epoch-1):
outfile=os.path.join(params.checkpoint_dir, '{:d}.tar'.format(epoch))
torch.save({'epoch':epoch, 'state':model.state_dict()}, outfile)
print("a epoch cost {} s".format(time.time() -start_epoch_time))
this means for each epoch, we do a validation process for model. if I set the --method baseline, according to the comment we should get the acc -1 returned. But I found that it always returned 0. Then I found the test_loop function for baseline as below:
deftest_loop(self, val_loader=None):
ifval_loaderisnotNone:
num_correct=0num_total=0num_correct_jigsaw=0num_total_jigsaw=0fori, inputsinenumerate(val_loader):
x=inputs[0]
y=inputs[1]
ifself.jigsaw:
loss_proto, loss_jigsaw, acc, acc_jigsaw=self.forward_loss(x, y, inputs[2], inputs[3])
loss= (1.0-self.lbda) *loss_proto+self.lbda*loss_jigsawnum_correct_jigsaw=int(acc_jigsaw*len(inputs[3]))
num_total_jigsaw+=len(inputs[3].view(-1))
elifself.rotation:
loss_proto, loss_rotation, acc, acc_rotation=self.forward_loss(x, y, inputs[2], inputs[3])
loss= (1.0-self.lbda) *loss_proto+self.lbda*loss_rotationnum_correct_jigsaw=int(acc_jigsaw*len(inputs[3]))
num_total_jigsaw+=len(inputs[3].view(-1))
else:
loss, acc=self.forward_loss(x,y)
num_correct+=int(acc*x.shape[0])
num_total+=len(y)
ifself.jigsaworself.rotation:
returnnum_correct*100.0/num_total, num_correct_jigsaw*100.0/num_total_jigsawelse:
returnnum_correct*100.0/num_totalelse:
ifself.jigsaw:
return-1, -1elifself.rotation:
return-1, -1else:
return-1#no validation, just save model during iteration
It says when val_loader is None, the acc will return -1. But in train.py, we set the val_loader is not None as below:
I found there is a comment in
train.py
as below:this means for each epoch, we do a validation process for model. if I set the
--method baseline
, according to the comment we should get the acc-1
returned. But I found that it always returned0
. Then I found thetest_loop
function forbaseline
as below:It says when
val_loader
is None, the acc will return -1. But intrain.py
, we set theval_loader
is not None as below:It means the
test_loop
function will useself.forward_loss
to computeloss
andacc
.My question is that why it always return

0
, whenval_loader
is notNone
?The text was updated successfully, but these errors were encountered: