Beispiel #1
0
def main(_argv):
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    os.environ["CUDA_VISIBLE_DEVICES"] = FLAGS.gpu

    logger = tf.get_logger()
    logger.disabled = True
    logger.setLevel(logging.FATAL)

    cfg = load_yaml(FLAGS.cfg_path)

    model = ArcFaceModel(size=cfg['input_size'],
                         backbone_type=cfg['backbone_type'],
                         training=False)

    ckpt_path = tf.train.latest_checkpoint('./checkpoints/' + cfg['sub_name'])
    if ckpt_path is not None:
        print('[*] load ckpt from {}'.format(ckpt_path))
        model.load_weights(ckpt_path)
    else:
        print('[*] Cannot find ckpt.')
        exit()

    if FLAGS.img_path:
        print("[*] Encode {} to ./output_embeds.npy".format(FLAGS.img_path))
        img = cv2.imread(FLAGS.img_path)
        img = cv2.resize(img, (cfg['input_size'], cfg['input_size']))
        img = img.astype(np.float32) / 255.
        if len(img.shape) == 3:
            img = np.expand_dims(img, 0)
        embeds = l2_norm(model(img))
        np.save('./output_embeds.npy', embeds)
    else:
        print("[*] Loading LFW, AgeDB30 and CFP-FP...")
        lfw, agedb_30, cfp_fp, lfw_issame, agedb_30_issame, cfp_fp_issame = \
            get_val_data(cfg['test_dataset'])

        print("[*] Perform Evaluation on LFW...")
        acc_lfw, best_th = perform_val(
            cfg['embd_shape'], cfg['batch_size'], model, lfw, lfw_issame,
            is_ccrop=cfg['is_ccrop'])
        print('    acc {:.4f}, th: {:.2f}'.format(acc_lfw, best_th))

        print("[*] Perform Evaluation on AgeDB30...")
        acc_agedb30, best_th = perform_val(
            cfg['embd_shape'], cfg['batch_size'], model, agedb_30,
            agedb_30_issame, is_ccrop=cfg['is_ccrop'])
        print('    acc {:.4f}, th: {:.2f}'.format(acc_agedb30, best_th))

        print("[*] Perform Evaluation on CFP-FP...")
        acc_cfp_fp, best_th = perform_val(
            cfg['embd_shape'], cfg['batch_size'], model, cfp_fp, cfp_fp_issame,
            is_ccrop=cfg['is_ccrop'])
        print('    acc {:.4f}, th: {:.2f}'.format(acc_cfp_fp, best_th))
Beispiel #2
0
def main(_argv):
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    os.environ['CUDA_VISIBLE_DEVICES'] = FLAGS.gpu

    logger = tf.get_logger()
    logger.disabled = True
    logger.setLevel(logging.FATAL)
    set_memory_growth()

    cfg = load_yaml(FLAGS.cfg_path)

    model = ArcFaceModel(size=cfg['input_size'],
                         backbone_type=cfg['backbone_type'],
                         training=False)

    ckpt_path = tf.train.latest_checkpoint('./checkpoints/' + cfg['sub_name'])
    if ckpt_path is not None:
        print("[*] load ckpt from {}".format(ckpt_path))
        model.load_weights(ckpt_path)
    else:
        print("[*] Cannot find ckpt from {}.".format(ckpt_path))
        exit()

    print("[*] Loading LFW, AgeDB30 and CFP-FP...")
    lfw, agedb_30, cfp_fp, lfw_issame, agedb_30_issame, cfp_fp_issame = \
        get_val_data(cfg['test_dataset'])

    print("[*] Perform Evaluation on LFW...")
    acc_lfw, best_th = perform_val(
        cfg['embd_shape'], cfg['batch_size'], model, lfw, lfw_issame,
        is_ccrop=cfg['is_ccrop'])
    print("    acc {:.4f}, th: {:.2f}".format(acc_lfw, best_th))

    print("[*] Perform Evaluation on AgeDB30...")
    acc_agedb30, best_th = perform_val(
        cfg['embd_shape'], cfg['batch_size'], model, agedb_30,
        agedb_30_issame, is_ccrop=cfg['is_ccrop'])
    print("    acc {:.4f}, th: {:.2f}".format(acc_agedb30, best_th))

    print("[*] Perform Evaluation on CFP-FP...")
    acc_cfp_fp, best_th = perform_val(
        cfg['embd_shape'], cfg['batch_size'], model, cfp_fp, cfp_fp_issame,
        is_ccrop=cfg['is_ccrop'])
    print("    acc {:.4f}, th: {:.2f}".format(acc_cfp_fp, best_th))
Beispiel #3
0
def main(_argv):
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    os.environ['CUDA_VISIBLE_DEVICES'] = FLAGS.gpu

    logger = tf.get_logger()
    logger.disabled = True
    logger.setLevel(logging.FATAL)
    set_memory_growth()

    cfg = load_yaml(FLAGS.cfg_path)

    model = ArcFaceModel(size=cfg['input_size'],
                         backbone_type=cfg['backbone_type'],
                         training=False)

    ckpt_path = tf.train.latest_checkpoint('./checkpoints/' + cfg['sub_name'])
    if ckpt_path is not None:
        print("[*] load ckpt from {}".format(ckpt_path))
        model.load_weights(ckpt_path)
    else:
        print("[*] Cannot find ckpt from {}.".format(ckpt_path))
        exit()

    if FLAGS.img_path:

        print("[*] Encode {} to ./output_embeds.npy".format(FLAGS.img_path))

        # file_dir = "C:/Users/chaehyun/PycharmProjects/ArcFace37_TF2x/data/AFDB_masked_face_dataset/*"
        file_dir = "C:/Users/smgg/Desktop/dataset/superjunior/*.jpg"
        # detector = MTCNN()
        i = 0
        img_list = glob.glob(file_dir)
        for i_list in img_list:
            img = cv2.cvtColor(cv2.imread(i_list), cv2.COLOR_BGR2RGB)
            detector = MTCNN()
            data_list = detector.detect_faces(img)

            for data in data_list:
                xmin, ymin, width, height = data['box']
                xmax = xmin + width
                ymax = ymin + height

                face_image = img[ymin:ymax, xmin:xmax, :]
                face_image = cv2.cvtColor(face_image, cv2.COLOR_RGB2BGR)
                cv2.imshow('', face_image)

                print(i_list)

                img_resize = cv2.resize(face_image,
                                        (cfg['input_size'], cfg['input_size']))
                cv2.imwrite("./{}.jpg".format(i), img_resize)
                cv2.imshow('', img_resize)
                cv2.waitKey(0)
                i = i + 1

                cv2.putText(img, "0", (xmin, ymin - 10),
                            cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 1,
                            cv2.LINE_AA)
                cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 1)

                img_resize = img_resize.astype(np.float32) / 255.
                if len(img_resize.shape) == 3:
                    img_resize = np.expand_dims(img_resize, 0)
                embeds = l2_norm(model(img_resize))

                #print('./newTWICE_id/{}.npy'.format(i_list.split('/')[6].split('\\')[1].split('.jpg')[0]))
                np.save(
                    './newTWICE_id/{}.npy'.format(
                        i_list.split('/')[5].split('\\')[1].split('.jpg')[0]),
                    embeds)
    else:
        print("[*] Loading LFW, AgeDB30 and CFP-FP...")
        lfw, agedb_30, cfp_fp, lfw_issame, agedb_30_issame, cfp_fp_issame = \
            get_val_data(cfg['test_dataset'])

        print("[*] Perform Evaluation on LFW...")
        acc_lfw, best_th = perform_val(cfg['embd_shape'],
                                       cfg['batch_size'],
                                       model,
                                       lfw,
                                       lfw_issame,
                                       is_ccrop=cfg['is_ccrop'])
        print("    acc {:.4f}, th: {:.2f}".format(acc_lfw, best_th))

        print("[*] Perform Evaluation on AgeDB30...")
        acc_agedb30, best_th = perform_val(cfg['embd_shape'],
                                           cfg['batch_size'],
                                           model,
                                           agedb_30,
                                           agedb_30_issame,
                                           is_ccrop=cfg['is_ccrop'])
        print("    acc {:.4f}, th: {:.2f}".format(acc_agedb30, best_th))

        print("[*] Perform Evaluation on CFP-FP...")
        acc_cfp_fp, best_th = perform_val(cfg['embd_shape'],
                                          cfg['batch_size'],
                                          model,
                                          cfp_fp,
                                          cfp_fp_issame,
                                          is_ccrop=cfg['is_ccrop'])
        print("    acc {:.4f}, th: {:.2f}".format(acc_cfp_fp, best_th))
Beispiel #4
0
                         backbone_type=cfg['backbone_type'],
                         training=False)

    if which_datatest == 'lfw':
        dataset_test_path = 'lfw_align_112/lfw'
    elif which_datatest == 'agedb':
        dataset_test_path = 'agedb_align_112/agedb_30'
    elif which_datatest == 'cfp':
        dataset_test_path = 'cfp_align_112/cfp_fp'
    else:
        dataset_test_path = which_datatest

    print("[*] Loading dataset test {}...".format(which_datatest))

    dataset_test, dataset_test_issame = \
            get_val_data(cfg['test_dataset'],dataset_test_path)

    test_summary_writer = tf.summary.create_file_writer(cfg['logs_dir'] +
                                                        cfg['sub_name'] +
                                                        '/test_' +
                                                        which_datatest)

    checkpoint_dir = os.path.join(cfg['checkpoints_dir'], cfg['sub_name'])
    ckpt_path = None

    steps_per_epoch = cfg['num_samples'] // cfg['batch_size']

    while True:

        new_ckpt_path = wait_for_new_checkpoint(checkpoint_dir, ckpt_path)
        ckpt_path = new_ckpt_path