Beispiel #1
0
                        '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(
                            'Epoch {}/{}, {} average acc:{:.4f} average threshold:{:.4f}'
                            .format(epoch, args.epoch - 1, phase,
                                    np.mean(ACCs) * 100, np.mean(threshold)) +
                            '\n')
Beispiel #2
0
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    # from face_model import MobileFaceNet, l2_norm
    from collections import namedtuple
    dataloaders , dataset_sizes, dataset = load_test_data(50)
    Genotype = namedtuple('Genotype', 'normal normal_concat reduce reduce_concat')
    genotype = Genotype(normal=[('skip_connect', 1), ('sep_conv_3x3', 0), ('sep_conv_3x3', 0), ('skip_connect', 1), ('sep_conv_3x3', 1), ('sep_conv_3x3', 3), ('sep_conv_3x3', 1), ('dil_conv_5x5', 4)], normal_concat=range(2, 6), reduce=[('sep_conv_3x3', 0), ('skip_connect', 1), ('dil_conv_5x5', 2), ('max_pool_3x3', 1), ('sep_conv_3x3', 2), ('sep_conv_3x3', 1), ('sep_conv_5x5', 0), ('sep_conv_3x3', 3)], reduce_concat=range(2, 6))
    from face_search.model_search_ms1m import Network
    model =NetworkImageNet(48, 85742, 14, genotype).to(device)
    # print(model)/data/face_recognition/1MobileFaceNet_Tutorial_Pytorch-master1/saving_Faces_emore_ckpt/Iter_009000_margin.ckpt
    checkpoint=torch.load('best_arc64\Iter_725000_model.ckpt')
    # model = MobileFaceNet(512).to(device)
    # state_dict = torch.load('arc_center_focal\Iter_555000_model.ckpt')['net_state_dict']
    # from collections import OrderedDict
    # new_state_dict = OrderedDict()
    # for k, v in state_dict.items():
    #     name = k[7:] # remove `module.`
    #     new_state_dict[name] = v
    # load params
    model.load_state_dict(state_dict)
    # print(state_dict)
    # model.drop_path_prob = 0
    model.eval()
    
    for phase in ['LFW', 'CFP_FP', 'AgeDB30','privacy']:                 
        featureLs, featureRs = getFeature(model, dataloaders[phase], device, flip = True)
        # ACCs, threshold = evaluation_10_fold(featureLs, featureRs, dataset[phase], method = 'l2_distance')
        ACCs, threshold = evaluation_10_fold(featureLs, featureRs, dataset[phase], method = 'cos_distance')
        print('Epoch {}/{},{} average acc:{:.4f} average threshold:{:.4f}'.format(1, 1, phase, np.mean(ACCs) * 100, np.mean(threshold)))