'Iter_%06d_model.ckpt' % total_iters)) torch.save( { 'iters': total_iters, 'net_state_dict': margin.state_dict() }, os.path.join(save_dir, 'Iter_%06d_margin.ckpt' % total_iters)) # evaluate accuracy if total_iters % 3000 == 0: model.eval() for phase in ['LFW', 'CFP_FP', 'AgeDB30']: featureLs, featureRs = getFeature(model, dataloaders[phase], device, flip=args.flip) ACCs, threshold = evaluation_10_fold(featureLs, featureRs, dataset[phase], method=args.method) print( 'Epoch {}/{},{} average acc:{:.4f} average threshold:{:.4f}' .format(epoch, args.epoch - 1, phase, np.mean(ACCs) * 100, np.mean(threshold))) if best_acc[phase] <= np.mean(ACCs) * 100: best_acc[phase] = np.mean(ACCs) * 100 best_iters[phase] = total_iters with open(test_logging_file, 'a') as f: f.write(
torch.save({ 'iters': total_iters, 'net_state_dict': model.state_dict()}, os.path.join(save_dir, 'Iter_%06d_model.ckpt' % total_iters)) torch.save({ 'iters': total_iters, 'net_state_dict': margin.state_dict()}, os.path.join(save_dir, 'Iter_%06d_margin.ckpt' % total_iters)) # evaluate accuracy if total_iters % 3000 == 0: model.eval() for phase in ['LFW', 'CFP_FP', 'AgeDB30']: featureLs, featureRs = getFeature(model,best_arc, dataloaders[phase], "cuda:1", flip = args.flip,) ACCs, threshold = evaluation_10_fold(featureLs, featureRs, dataset[phase], method = args.method) print('Epoch {}/{},{} average acc:{:.4f} average threshold:{:.4f}' .format(epoch, args.epoch-1, phase, np.mean(ACCs) * 100, np.mean(threshold))) if best_acc[phase] <= np.mean(ACCs) * 100: best_acc[phase] = np.mean(ACCs) * 100 best_iters[phase] = total_iters with open(test_logging_file, 'a') as f: f.write('Epoch {}/{}, {} average acc:{:.4f} average threshold:{:.4f}' .format(epoch, args.epoch-1, phase, np.mean(ACCs) * 100, np.mean(threshold))+'\n') f.close() model.train() time_elapsed = time.time() - start