• 大小: 6.94M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-10
  • 语言: Python
  • 标签: 检测  

资源简介


在本工程中我们开源了活体模型训练架构,数据预处理方法,模型训练和测试脚本以及开源的APK供大家测试使用。 活体检测技术主要是判别机器前出现的人脸是真实还是伪造的,其中借助其他媒介呈现的人脸都可以定义为虚假的人脸,包括打印的纸质照片、电子产品的显示屏幕、硅胶面具、立体的3D人像等。目前主流的活体解决方案分为配合式活体检测和非配合式活体检测(静默活体检测)。配合式活体检测需要用户根据提示完成指定的动作,然后再进行活体校验,静默活体则在用户无感的情况下直接进行活体校验。 

因傅里叶频谱图一定程度上能够反应真假脸在频域的差异,因此我们采用了一种基于傅里叶频谱图辅助监督的静默活体检测方法, 模型架构由分类主分支和傅里叶频谱图辅助监督分支构成 

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
# @Time : 20-6-9 下午3:06
# @Author : zhuying
# @Company : Minivision
# @File : test.py
# @Software : PyCharm

import os
import cv2
import numpy as np
import argparse
import warnings
import time

from src.anti_spoof_predict import AntiSpoofPredict
from src.generate_patches import CropImage
from src.utility import parse_model_name
warnings.filterwarnings(‘ignore‘)


SAMPLE_IMAGE_PATH = “./images/sample/“


# 因为安卓端APK获取的视频流宽高比为3:4为了与之一致,所以将宽高比限制为3:4
def check_image(image):
    height width channel = image.shape
    if width/height != 3/4:
        print(“Image is not appropriate!!!\nHeight/Width should be 4/3.“)
        return False
    else:
        return True


def test(image_name model_dir device_id):
    model_test = AntiSpoofPredict(device_id)
    image_cropper = CropImage()
    image = cv2.imread(SAMPLE_IMAGE_PATH + image_name)
    result = check_image(image)
    if result is False:
        return
    image_bbox = model_test.get_bbox(image)
    prediction = np.zeros((1 3))
    test_speed = 0
    # sum the prediction from single model‘s result
    for model_name in os.listdir(model_dir):
        h_input w_input model_type scale = parse_model_name(model_name)
        param = {
            “org_img“: image
            “bbox“: image_bbox
            “scale“: scale
            “out_w“: w_input
            “out_h“: h_input
            “crop“: True
        }
        if scale is None:
            param[“crop“] = False
        img = image_cropper.crop(**param)
        start = time.time()
        prediction += model_test.predict(img os.path.join(model_dir model_name))
        test_speed += time.time()-start

    # draw result of prediction
    label = np.argmax(prediction)
    value = prediction[0][label]/2
    if label == 1:
        print(“Image ‘{}‘ is Real Face. Score: {:.2f}.“.format(image_name value))
        result_text = “RealFace Score: {:.2f}“.format(value)
        color = (255 0 0)
    else:
        print(“Image ‘{}‘ is Fake Face. Score: {:.2f}.“.format(image_name value))
        result_text = “FakeFace Score: {:.2f}“.format(value)
        color = (0 0 255)
    print(“Prediction cost {:.2f} s“.format(test_speed))
    cv2.rectangle(
        image
        (image_bbox[0] image_bbox[1])
        (image_bbox[0] + image_bbox[2] image_bbox[1] + image_bbox[3])
        color 2)
    cv2.putText(
        image
        result_text
        (image_bbox[0] image_bbox[1] - 5)
        cv2.FONT_HERSHEY_COMPLEX 0.5*image.shape[0]/1024 color)

    format_ = os.path.splitext(image_name)[-1]
    result_image_name = image_name.replace(format_ “_result“ + format_)
    cv2.imwrite(SAMPLE_IMAGE_PATH + result_image_name image)


if __name__ == “__main__“:
    desc = “test“
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument(
        “--device_id“
        type=int
        default=0
        help=“which gpu id [0/1/2/3]“)
    parser.add_argument(
        “--model_dir“
        type=st

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\
     文件           5  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\.gitignore
     文件       11340  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\LICENSE
     文件        5997  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\README.md
     文件        6642  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\README_EN.md
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\datasets\
     文件         370  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\datasets\README.md
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\
     文件     1440225  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\demo.gif
     文件       35893  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\framework.jpg
     文件      131303  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\logo.jpg
     文件       49391  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\patch_demo.png
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\sample\
     文件       64962  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\sample\image_F1.jpg
     文件       66169  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\sample\image_F1_result.jpg
     文件       86332  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\sample\image_F2.jpg
     文件       87519  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\sample\image_F2_result.jpg
     文件       74168  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\sample\image_T1.jpg
     文件       75109  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\sample\image_T1_result.jpg
     文件       40753  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\设置阈值.png
     文件       26471  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\images\静默活体APK.jpeg
     文件         129  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\requirements.txt
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\resources\
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\resources\anti_spoof_models\
     文件     1849453  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\resources\anti_spoof_models\2.7_80x80_MiniFASNetV2.pth
     文件     1856130  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\resources\anti_spoof_models\4_0_0_80x80_MiniFASNetV1SE.pth
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\resources\detection_model\
     文件     1866013  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\resources\detection_model\Widerface-RetinaFace.caffemodel
     文件       40787  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\resources\detection_model\deploy.prototxt
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\saved_logs\
     目录           0  2020-08-05 05:53  Silent-Face-Anti-Spoofing-master\saved_logs\jobs\
............此处省略19个文件信息

评论

共有 条评论