资源简介
在本工程中我们开源了活体模型训练架构,数据预处理方法,模型训练和测试脚本以及开源的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\fr
文件 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个文件信息
- 上一篇:网易云课堂视频(python脚本)
- 下一篇:Python爬虫数据分析可视化
相关资源
- VGG16实现人脸检测
- 计算机视觉 opencv 检测不合格产品.
- 图片分类,图像识别,目标检测
- 人脸检测和识别(opencv3+python)
- python检测图片是否有人脸
- 以树莓派为基础,连接有毒气体传感
- tensorflow2.0 yolo3目标检测算法
- Python-直播答题助手自动检测出题搜索
- Python-本项目基于yolo3与crnn实现中文自
- python火焰检测颜色模型代码
- miller_rabin检测生成大素数的RSA算法实
- python基于人脸检测和人脸识别
- Python-Insightface人脸检测识别的最小化
- Python-自然场景文本检测PSENet的一个
- Python-基于YOLOv3的行人检测
- Python-高效准确的EAST文本检测器的一个
- Python-pytorch实现的人脸检测和人脸识别
- Python-机器学习驱动的Web应用程序防火
- Python-神经网络模型能够从音频演讲中
- 基于OpenCV 的回转体零件表面缺陷检测
- Python 数据分析之金融欺诈行为检测
- 人体姿态检测
- 安全帽检测detect.7z
- 10行Python代码实现目标检测
- opencv3+python人脸检测和识别- 完整实战
- opencv3+python人脸检测和识别- 完整实战
- opencv3+python人脸检测和识别 完整项目
- opencv3视频中检测人脸python
- 5. 深度学习中的目标检测 python代码实
- 基于hough直线检测的倾斜图片校正
评论
共有 条评论