Git Product home page Git Product logo

awesome_face_antispoofing's Introduction

awesome_face_antispoofing

  • This is a single shot face anti-spoofing project.
  • The deep learning framework is Pytorch. Python3.5 is used.

Installation

  • sudo -s
  • sh install_requirements.sh
  • exit

Face landmarks

  • face_alignment is used for landmarks extraction. Page face_alignment. Thanks to them.

Landmarks extraction scripts

  • cd detlandmark&&python3 detlandmark_imgs.py NUAA_raw_dir

Data

  • I have upload data and detected landmarks into GOOGLE DRIVE-raw.tar.gz

  • I have upload data and detected landmarks into Baidu DRIVE-raw.tar.gz

  • You can change corresponding directory and filename in config.py

  • For example train_filelists=[ ['raw/ClientRaw','raw/client_train_raw.txt',GENUINE], ['raw/ImposterRaw','imposter_train_raw.txt',ATTACK] ] test_filelists=[ ['raw/ClientRaw','raw/client_test_raw.txt',GENUINE], ['raw/ImposterRaw','raw/imposter_test_raw.txt',ATTACK] ]

Method

  • Our method is straightforward. Small patched containing a face is cropped with corresponding landmarks. A binary classification network is used to distinguish the attack patches. alt text

Training

  • First, edit file config.py, choose the target network and proper batch_size.
  • Then, in terminal command: make clean&&make&&python3 main.py train

Inference

  • In terminal command: python3 inference.py inference --images='detlandmark/inference_images/*/*.jpg'
  • The inference report is result/inference.txt, you can check it in commad: cat result/inference.txt

Visualize Dataset

  • We have fixed the bug of choice wrong face in multiple detected faces with standard of coordinates.
  • To visualize cropped faces in dataset. Please run command: python3 vis_cropface.py visualize
  • All faces will be shown in data/showcropface_train.jpg and data/showcropface_val.jpg
  • The training data are shown here. Training Validation

Experiments

  • Experiments results on NUAA[1] Image input size is as same as the imagenet.
  • State-of-the-art networks are used, e.g. VGG[2], ResNet[3], DenseNet[4], Inception[5], Xception[6], DetNet[7]
Network Acc AUC EER TPR(1.0%) TPR(.5%)
VGG-11 0.9416 0.99600562 0.031592 0.948099 0.931262
VGG-13 0.9452 0.99261419 0.034890 0.908696 0.869814
VGG-16 0.9591 0.99449404 0.027599 0.952283 0.926575
VGG-19 0.9013 0.99623176 0.023086 0.958378 0.941503
Res-18 0.9813 0.99872778 0.008158 0.992470 0.989585
Res-34 0.9656 0.99978646 0.003992 0.998091 0.996181
Res-50 0.8677 0.99951550 0.008923 0.991668 0.986544
denseNet121 0.9803 0.99872628 0.014754 0.981534 0.970144
denseNet161 0.9757 0.99610439 0.016664 0.977222 0.967020
denseNet169 0.9334 0.99532942 0.029744 0.949662 0.932130
denseNet201 0.9263 0.99833348 0.012195 0.985718 0.975525
InceptionV3 0.8078 0.99172718 0.036278 0.927270 0.907655
Xception 0.9843 0.99973281 0.005728 0.996431 0.993101
DetNet 0.9072 0.99998322 0.000892 0.999705 0.999703

Reference

  • [1]Tan X, Li Y, Liu J, et al. Face liveness detection from a single image with sparse low rank bilinear discriminative model[C]// European Conference on Computer Vision. Springer-Verlag, 2010:504-517.
  • [2]Simonyan K, Zisserman A. Very deep convolutional networks for large-scale image recognition[J]. arXiv preprint arXiv:1409.1556, 2014.
  • [3]He K, Zhang X, Ren S, et al. Deep residual learning for image recognition[C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2016: 770-778.
  • [4]Huang G, Liu Z, Van Der Maaten L, et al. Densely connected convolutional networks[C]//CVPR. 2017, 1(2): 3.
  • [5]Szegedy C, Vanhoucke V, Ioffe S, et al. Rethinking the inception architecture for computer vision[C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2016: 2818-2826.
  • [6]Chollet F. Xception: Deep learning with depthwise separable convolutions[J]. arXiv preprint, 2017: 1610.02357.
  • [7]Li Z, Peng C, Yu G, et al. DetNet: A Backbone network for Object Detection[J]. arXiv preprint arXiv:1804.06215, 2018.

awesome_face_antispoofing's People

Contributors

jinghuizhou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

awesome_face_antispoofing's Issues

程序运行失败

小哥哥您好,很抱歉打扰到您,我在window10(无gpu )上用vs code 运行这个项目时出现了两个问题。
1:

image

2:我在使用MyresNet34网络的时候出现了           

AttributeError: ‘MyresNet34‘ object has no attribute ‘load’错误
可是我在config.py里面确确实实修改了配置,如下图:
image

这个问题困扰了我好多天,如果您愿意的话请给我一点指点,感激不尽!!!我的微信是18186473512,谢谢你

I am new need help.

myData, test= False
Traceback (most recent call last):
File "main.py", line 322, in
fire.Fire()
File "/anaconda3/lib/python3.7/site-packages/fire/core.py", line 127, in Fire
component_trace = _Fire(component, args, context, name)
File "/anaconda3/lib/python3.7/site-packages/fire/core.py", line 366, in _Fire
component, remaining_args)
File "/anaconda3/lib/python3.7/site-packages/fire/core.py", line 542, in _CallCallable
result = fn(*varargs, **kwargs)
File "main.py", line 100, in train
data_source='none')
File "/Users/b0074981/Desktop/facelivenesspython/2/data/require_dataset.py", line 39, in init
fopen = open(filedir,'r')
FileNotFoundError: [Errno 2] No such file or directory: '/home/cv/zjh/aich/dataset/raw/client_train_raw.txt'

Please help

Issue about input dimension of MultiscaleresNet18

Dear sir @JinghuiZhou, thanks for a great repository and many network architecture implementations. But i have an issue that i think the code need to do a little bit more configuration. When i was training Resnet18, Resnet30, VGG,... everything is ok. But when i switch to MultiscaleresNet18, i got a bug below

RuntimeError: Expected 4-dimensional input for 4-dimensional weight [64, 3, 7, 7], but got 5-dimensional input of size [2, 1, 3, 224, 224] instead

The error happens in the line summary(model, (3, 224, 224)) and the input of the model in main.py.
I think the code need a small change when training with MultiscaleresNet. But i couldn't find where to fix it. Can you show me how? Thanks a lot!!!

Can you implement mobilenet?

This is a great project, but I think if you can make the model smaller, that would be even better for embedded system...

Need some sample data also.

Please me how to train.

python3 main.py train
Traceback (most recent call last):
File "main.py", line 5, in
from data import myData
ModuleNotFoundError: No module named 'data'

About data and model

I saw your showcropface_train.jpg and showcropface_val.jpg. I found that most of the spoofing images contained the finger of the person holding the picture. So, the model might learn the finger instead of the difference between a real image and a spoofing image.

tensor(0.9837, device='cuda:0', dtype=torch.float64) is not JSON serializable

File "/home/lyn/awesome_face_antispoofing/utils/Visualizer.py", line 67, in plot_many_stack
update=None if x == 0 else 'append'
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/site-packages/visdom/init.py", line 335, in wrapped_f
return f(*args, **kwargs)
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/site-packages/visdom/init.py", line 1367, in line
update=update, name=name)
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/site-packages/visdom/init.py", line 335, in wrapped_f
return f(*args, **kwargs)
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/site-packages/visdom/init.py", line 1292, in scatter
return self._send(data_to_send, endpoint=endpoint)
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/site-packages/visdom/init.py", line 548, in _send
data=json.dumps(msg),
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/json/init.py", line 230, in dumps
return _default_encoder.encode(obj)
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/json/encoder.py", line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/json/encoder.py", line 256, in iterencode
return _iterencode(o, 0)
File "/root/anaconda3/envs/py35-torch-liveness/lib/python3.5/json/encoder.py", line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: tensor(0.9837, device='cuda:0', dtype=torch.float64) is not JSON serializable

Do you have any pretrained model available?

Hey,
I would like to test your network, yet I don't have the resources to train it myself from scratch. Could you provide a google drive / pan baidu link if possible?
Regards

Can you explain the network structure you used?

Did you use the pretrained models and remove the last two layers and add Convolution layer and fully connected layer, and then fintuned?
Did i understand your project correctly?

Thank you :)

Need inference.py

I noticed that you have uploaded some pretrained models. Is there any inference script for test these models? thx.

VGG-11 result are very poor

Hi, thanks for providing your interesting work.
I have an issue when implementing your code on VGG-11 with the NUAA dataset. I got
EER = 0.048105, TPR(1%) = 0.876410, TPR(.5%) = 0.831453, AUC = 0.98986704,
which huge difference from yours publish result.
Can u explain it?

Thanks

Facing issue on macbook pro. Pleas help

RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason. The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols. You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.

Bug report:About train_acc and val_acc show err in visdom

About main.py:line 229
In this part:
`vis.plot_many_stack({'train_loss': train_loss.value()[0],
'val_loss': val_loss.value()[0]}, win_name="Loss")

vis.plot_many_stack({'train_acc': train_acc.value()[0],
'val_acc': val_acc.value()[0]}, win_name='Acc')`

When using GPU training,var train_acc and val_acc should use
.cpu() to load in memory,So I change source code like this:
if opt.use_gpu: val_acc.add(v_accuracy.cpu()) else: val_acc.add(v_accuracy)
And
if opt.use_gpu: train_acc.add(epoch_acc.cpu()) else: train_acc.add(epoch_acc)

测试集准确率0.95,但是写前向测试代码测得结果很差

model_path = r'../data/model/71.pth'

model = getattr(models, 'MyresNet34')().eval()
if torch.cuda.is_available():
model = model.cuda()

model.load(model_path)

else:

model.load(model_path, map='cpu')

transformer = transforms.Compose([transforms.ToTensor()])#, transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])

def val(img):
img = maxcrop(img)
img = transformer(img)
if torch.cuda.is_available():
img = img.cuda()
img = img.view(1, *img.size())
with torch.no_grad():
val_input = Variable(img)

model.eval()
score = model(val_input)

outputs = torch.softmax(score, dim=-1)
preds = outputs[0].to('cpu').detach().numpy()

return preds

if name == 'main':
path = r'../data/img/val/y'
filelist = os.listdir(path)
for file in filelist:
image = os.path.join(path, file)
img = Image.open(image).convert('RGB')
res = val(img)
print(res)

An error with visdom

First ,thanks for your great work,it really helps me a lot.
The progress of train is OK. While try to put the result into visdom and visualize it,here is a problem:
TypeError: object of type 'Tensor' is not JSON serializable.
My Pytorch is 1.0.0, and some questions on StackOverflow tell me to change Pytorch 1.0.0 to 0.3.1, but when I tried that, it showed more problems. so give it up.
Can you give me some advice about that? thanks in advance.

Help Required

Can you please let me know what path or value i need to put here-

env = model # visdom 环境
train_root = '' # 训练集存放路径
val_root = '' # 验证集存放路径
test_root = 'data/AgriculturalDisease_testA/' # 测试集存放路径

some sample required please.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.