Giter VIP home page Giter VIP logo

transface's Introduction

TransFace

This is the official PyTorch implementation of [ICCV-2023] TransFace: Calibrating Transformer Training for Face Recognition from a Data-Centric Perspective.

Arxiv Version

ModelScope

You can quickly experience and invoke our TransFace model on the ModelScope.

  • Quickly utilize our model as a feature extractor to extract facial features from the input image.
# Usage: Input aligned facial images (112x112) to obtain a 512-dimensional facial feature vector.
# For convenience, the model integrates the RetinaFace model for face detection and keypoint estimation.
# Provide two images as input, and for each image, the model will independently perform face detection,
# select the largest face, align it, and extract the corresponding facial features.
# Finally, the model will return a similarity score indicating the resemblance between the two faces.

from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.outputs import OutputKeys
import numpy as np

face_mask_recognition_func = pipeline(Tasks.face_recognition, 'damo/cv_vit_face-recognition')
img1 = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/face_recognition_1.png'
img2 = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/face_recognition_2.png'
emb1 = face_mask_recognition_func(img1)[OutputKeys.IMG_EMBEDDING]
emb2 = face_mask_recognition_func(img2)[OutputKeys.IMG_EMBEDDING]
sim = np.dot(emb1[0], emb2[0])
print(f'Face cosine similarity={sim:.3f}, img1:{img1}  img2:{img2}')

Requirements

  • Install Pytorch (torch>=1.9.0)
  • pip install -r requirement.txt

Datasets

You can download the training datasets, including MS1MV2 and Glint360K:

You can download the test dataset IJB-C as follows:

How to Train Models

  1. You need to modify the path of training data in every configuration file in folder configs.

  2. To run on a machine with 8 GPUs:

python -m torch.distributed.launch --nproc_per_node=8 --nnodes=1 --node_rank=0 --master_addr="127.0.0.1" --master_port=12581 train.py 

How to Test Models

  1. You need to modify the path of IJB-C dataset in eval_ijbc.py.

  2. Run:

python eval_ijbc.py --model-prefix work_dirs/glint360k_vit_s/model.pt --result-dir work_dirs/glint360k_vit_s --network vit_s_dp005_mask_0 > ijbc_glint360k_vit_s.log 2>&1 &

TransFace Pretrained Models

You can download the TransFace models reported in our paper as follows:

Training Data Model IJB-C(1e-6) IJB-C(1e-5) IJB-C(1e-4) IJB-C(1e-3) IJB-C(1e-2) IJB-C(1e-1)
MS1MV2 TransFace-S 86.75 93.87 96.45 97.51 98.34 98.99
MS1MV2 TransFace-B 86.73 94.15 96.55 97.73 98.47 99.11
MS1MV2 TransFace-L 86.90 94.55 96.59 97.80 98.45 99.04
Training Data Model IJB-C(1e-6) IJB-C(1e-5) IJB-C(1e-4) IJB-C(1e-3) IJB-C(1e-2) IJB-C(1e-1)
Glint360K TransFace-S 89.93 96.06 97.33 98.00 98.49 99.11
Glint360K TransFace-B 88.64 96.18 97.45 98.17 98.66 99.23
Glint360K TransFace-L 89.71 96.29 97.61 98.26 98.64 99.19

You can test the accuracy of these model: (e.g. Glint360K TransFace-L)

python eval_ijbc.py --model-prefix work_dirs/glint360k_vit_l/glint360k_model_TransFace_L.pt --result-dir work_dirs/glint360k_vit_l --network vit_l_dp005_mask_005 > ijbc_glint360k_vit_l.log 2>&1 &

Citation

  • If you find it helpful for you, please cite our paper
@inproceedings{dan2023transface,
  title={TransFace: Calibrating Transformer Training for Face Recognition from a Data-Centric Perspective},
  author={Dan, Jun and Liu, Yang and Xie, Haoyu and Deng, Jiankang and Xie, Haoran and Xie, Xuansong and Sun, Baigui},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  pages={20642--20653},
  year={2023}
}

Acknowledgments

We thank Insighface for the excellent code base.

transface's People

Contributors

danjun6737 avatar

Stargazers

Bert Fan avatar  avatar Dheny Dwi Prakoso avatar Alexey Golunov avatar fourmi avatar  avatar yuyingmelody avatar  avatar Luke Chang avatar  avatar  avatar Jana Jovičić avatar  avatar miaosonic avatar Jaehoon.Lee avatar  avatar  avatar Fei avatar JP avatar  avatar Yuan Zhi avatar 韩锋 avatar Duanxian0x0 avatar  avatar KeonHo avatar Keivan Bahmani avatar Linyz avatar Junwen Chen avatar  avatar Pavly Salah avatar BigCowPeking avatar Weixi Xiang avatar  avatar  avatar  avatar Seonho Oh avatar fun_dl avatar Yiming Lin avatar SandwichFish avatar Richard Chen avatar 爱可可-爱生活 avatar Sejong Yang avatar Ha Le avatar  avatar  avatar Xiang An avatar JiankangDeng avatar

Watchers

 avatar

transface's Issues

Pretrained Weights

Thank you for your excellent work!
I would like to finetune the network based on the pre-trained weights. Could you please provide them like "work_dirs/glint360k_vit_l/glint360k_model_TransFace_L.pt" you've mentioned?
Thanks in advance.

The Train log

Can you provide your train log?The loss in the early stages of training are much higher than normal Vit

TopK tensor, weight, 2 loss

TopK = TopK_ALL[:, :K]
local_embeddings, weight, local_patch_entropy = backbone(img_fft)
double loss: torch.Tensor = module_partial_fc(local_embeddings, local_labels, opt, local_patch_entropy)

above TopK tensor, weight,all not to used.
2 loss also was not used in combination.

模型推理cpu占用高,gpu几乎不占用

大佬你好,我在调用这个模型推理的时候,发现cpu占用很高,但是gpu占用却几乎不升高,但是加载模型后显存占用确实变高了,至少是用到了显卡的,不知道是不是加载模型的时候没有完全加载到显卡中,调用和推理代码不是完全用的给出的demo,我把人脸检测和对齐部分用其他方法实现了,能帮我看看代码吗,谢谢

User Warning

Hi,

When I tried to train the model with customized datasets, it shows this user warning.
' UserWarning: None of the inputs have requires_grad=True. Gradients will be None warnings.warn("None of the inputs have requires_grad=True. Gradients will be None")' How can I fix this warning? Will it affect the model performance? Thanks!

Results for WebFace42M

Hello,

Really nice work!

But why do you not provide any experimental results using WebFace42M as the training dataset?
It is more "large-scale" dataset compared to Glint360K and that's why it is more natural to train ViT-based architectures using it.

Thank you!

Inference questions

@DanJun6737 thank you for your work.

I would like to ask the following:

  1. for inferencing on own images, can i use this file?
  2. if i am using this through modelscope, how do i specify certain models?

train the model using my own images

when I trained the model using my own images,how to fix the config.val_targets in the config. I always got the error: stack expects each tensor to be equal size,bot got [3,364,458] at entry 0 and [3,215,317] at entry 1

Vit-L config

Can you provide VitL config to train glint360k?

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.