• 大小: 74.91MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2022-11-26
  • 语言: 其他
  • 标签: 活体检测  NUAA  

资源简介

1)需要下载NUAA数据集;2)结合NUAA数据集,完成根据list读取数据集,embedding,之后训练一个活体检测模型;3)测试模型的性能

资源截图

代码片段和文件信息

from os import listdir
from pickle import dump
import keras
from keras.applications.vgg16 import VGG16
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
from keras.models import Model

#saved as C:\Users\Administrator\.keras\models
def extract_features(directorytarget_size):

model = VGG16()
#Modify model to remove the last layer
model.layers.pop()
model = Model(inputs=model.inputsoutputs=model.layers[-1].output)
print(model.summary())

for sub_dir in listdir(directory):
if sub_dir == ‘.DS_Store‘:
continue

if sub_dir == ‘ImposterRaw‘:

features = {}
subdirectory = directory + “/“+ sub_dir

for subsub in listdir(subdirectory):
if subsub == “.DS_Store“:
continue

subsubdirectory = subdirectory + “/“ + subsub

for img_name in listdir(subsubdirectory):
filename = subsubdirectory+ “/“ + img_name
if img_name == ‘Thumbs.db‘ or img_name == ‘.DS_Store‘:
continue

image = load_img(filenametarget_size=(target_sizetarget_size))
image = img_to_array(image)

image = image.reshape((1 image.shape[0] image.shape[1] image.shape[2]))
# prepare the image for the VGG model
image = preprocess_input(image)
# get features
img_feature = model.predict(image verbose=0)
# store feature
features[subsub+“\\“+img_name] = img_feature
print(‘>%s‘ % filename)
dump(features open(“ImposterRaw“ + “.pkl“ ‘wb‘))

if sub_dir == ‘ClientRaw‘:

features = {}
subdirectory = directory + “/“ + sub_dir

for subsub in listdir(subdirectory):
if subsub == “.DS_Store“:
continue

subsubdirectory = subdirectory + “/“ + subsub

for img_name in listdir(subsubdirectory):
filename = subsubdirectory+ “/“ + img_name
if img_name == ‘Thumbs.db‘ or img_name == ‘.DS_Store‘:
continue

image = load_img(filename target_size=(target_size target_size))
image = img_to_array(image)

image = image.reshape((1 image.shape[0] image.shape[1] image.shape[2]))
# prepare the image for the VGG model
image = preprocess_input(image)
# get features
img_feature = model.predict(image verbose=0)
# store feature
features[subsub + “\\“ + img_name] = img_feature
print(‘>%s‘ % filename)
dump(features open(“ClientRaw“+“.pkl“ ‘wb‘))



img_features = extract_features(“G:\\人脸活体检测\\db\\raw“224)



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-02-27 15:59  NUAA_Face-anti-spoofing\
     文件    84128685  2019-02-27 15:55  NUAA_Face-anti-spoofing\ClientRaw.pkl
     文件   123746064  2019-02-27 15:57  NUAA_Face-anti-spoofing\ImposterRaw.pkl
     文件        1317  2018-07-20 04:58  NUAA_Face-anti-spoofing\README.md
     文件       93425  2010-10-15 19:22  NUAA_Face-anti-spoofing\client_test_raw.txt
     文件       48404  2010-10-15 19:18  NUAA_Face-anti-spoofing\client_train_raw.txt
     文件        2482  2019-02-27 15:52  NUAA_Face-anti-spoofing\create_embeddings.py
     文件      160034  2010-10-15 19:28  NUAA_Face-anti-spoofing\imposter_test_raw.txt
     文件       48562  2010-10-15 19:25  NUAA_Face-anti-spoofing\imposter_train_raw.txt
     文件        4379  2018-07-20 04:58  NUAA_Face-anti-spoofing\model.py

评论

共有 条评论