CVLFace Toolkit
repository·main·Indexed 42 days ago
https://github.com/mk-minchul/cvlfaceA high-performance, all-in-one toolkit for face recognition research. CVLFace supports multi-GPU training via PyTorch Lightning, large-scale evaluation, and face alignment. It integrates with Hugging Face and Wandb, providing access to state-of-the-art pre-trained models and architectures such as ViT KPRPE, IR101, and IR50, utilizing loss functions like AdaFace and Arc-Face.
What's inside CVLFace
- CVLface is an all-in-one toolkit designed for advanced face recognition research. It provides a simple and extendable platform that integrates modern machine learning frameworks including PyTorch, Lightning, Hugging Face, and Wandb. The toolkit is specifically designed to facilitate rapid experimentation by allowing users to download models and datasets on the fly.
Understand the CVLFace training dataset structure
mainCVLFace uses
.recfiles (optimized for high-performance I/O) organized into directories. The directory name must match therecfield in your dataset configuration YAML file.Example YAML configuration:
data_root: ${oc.env:DATA_ROOT} rec: 'casia_webface' color_space: 'RGB' num_classes: 10572 num_image: 490623 repeated_sampling_cfg: null semi_sampling_cfg: nullIn this example, the toolkit expects the dataset files to be located at
$DATA_ROOT/casia_webface/.Manage and interpret experiment results
mainAll experimental outputs are stored in the
experiments/directory. Results are organized hierarchically to allow for easy comparison between different code versions and individual trials.Results Naming Convention
Results are saved using the following pattern:
{folder_name}/{optional_prefix}_{Month}-{Date}_{Trial}Example Structure
experiments/ run_v1/ run_02-15_0/ new_loss_v1/ optim_sgd_02-15_0/ optim_adam_02-15_1/ bugfix_02-16_0/ new_loss_v2/ batchsize100_03-12_0/Directory structure for Face Alignment
mainThe app expects and maintains a directory structure similar to the following:
├── images/ # Directory containing original unaligned images │ ├── image1.jpg │ ├── subfolder/image2.png │ ... └── aligned_images/ # Directory where the aligned images will be saved │ ├── image1.jpg │ ├── subfolder/image2.png │ ...Organize and name experiment results
mainExperimental results are stored in the
experiments/directory. To facilitate easy comparison and navigation, results must follow a specific naming convention that links them back to their source code folder.Results Naming Convention:
{folder_name}/{optional_prefix}_{Month}-{Date}_{Trial}Example Structure: If you are running an experiment in the
new_loss_v1folder using the Adam optimizer, your results might be stored asexperiments/new_loss_v1/optim_adam_02-15_1/.experiments/ run_v1/ run_02-15_0/ new_loss_v1/ optim_sgd_02-15_0/ new_loss_v1/ optim_adam_02-15_1/ new_loss_v1/ bugfix_02-16_0/ new_loss_v2/ batchsize100_03-12_0/ new_architecture_v1_04-14_0/Understand the CVLFace dataset structure and configuration
mainCVLFace uses
.recfiles (optimized for high-performance I/O) organized into directories. The directory name must match therecfield in your dataset's YAML configuration file.For example, if your YAML config contains
rec: 'casia_webface', the toolkit will look for the dataset in$DATA_ROOT/casia_webface/.Example Directory Structure:
$DATA_ROOT ├── casia_webface │ ├── train.rec │ ├── train.idx │ └── train.tsv ├── webface260m/WebFace4M │ ├── train.rec │ ├── train.idx │ ├── train.tsv │ └── ldmk_5points.csv └── ...data_root: ${oc.env:DATA_ROOT} rec: 'casia_webface' color_space: 'RGB' num_classes: 10572 num_image: 490623 repeated_sampling_cfg: null semi_sampling_cfg: nullInstall RPE operations via setup.py
mainTo install the RPE (Relative Position Encoding) operations, navigate to the specific directory within the model structure and run the
setup.pyscript with the--userflag to install it for the current user.cd models/vit_kprpe/RPE/rpe_ops python setup.py install --userSet up WebFace12M dataset
mainWebFace12M requires obtaining a download link and password from face-benchmark.org.
- Download all zipfiles from the
0,1,2folders and place them in a directory. - Unzip them into
$DATA_ROOT/webface260m/temp. - Rename the extracted folder to
$DATA_ROOT/webface260m/WebFace12M. - Bundle the images into a
.recfile usingbundle_images_into_rec.py.
Optional: To prepare landmarks, run
predict_landmark.py.DATA_ROOT=/path/to/data_root mkdir -p $DATA_ROOT/webface260m/temp # After unzipping all 0_*.zip, 1_*.zip, 2_*.zip files into $DATA_ROOT/webface260m/temp: mv $DATA_ROOT/webface260m/temp/WebFace260M $DATA_ROOT/webface260m/WebFace12M rm -rf $DATA_ROOT/webface260m/temp # Bundle images into rec file python bundle_images_into_rec.py --source_dir $DATA_ROOT/webface260m/WebFace12M --remove_images # Optional: Prepare landmarks python predict_landmark.py --source_dir $DATA_ROOT/webface260m/WebFace12M- Download all zipfiles from the
Configure CVLFace environment variables
mainAfter installation, you must configure the environment variables in
cvlface/.env. Required or recommended variables include:DATA_ROOT: Path to your datasets.HF_TOKEN: Your Hugging Face Hub token (for downloading models).WANDB_TOKEN: Your Weights & Biases token.
Edit the file using a text editor like vim:
cd cvlface vim .envcd cvlface vim .env # edit the following environ variables """(content to add to .env) DATA_ROOT="YOUR_PATH_TO_DATA" HF_TOKEN="YOUR_HUGGINGFACE_HF_TOKEN" WANDB_TOKEN="YOUR_WANDB_TOKEN" """Download pre-trained models from Google Drive
mainIf you are using the CVLFace research code, you can download model files directly from Google Drive. After downloading, you must place the files in specific directories within your local CVLFace repository to ensure the toolkit can locate them.
Required Directory Structure:
- Recognition models:
cvlface/pretrained_models/recognition - Alignment models:
cvlface/pretrained_models/alignment
# Example directory placement # Move recognition models to: cp path/to/downloaded/recognition_model.pth cvlface/pretrained_models/recognition/ # Move alignment models to: cp path/to/downloaded/alignment_model.pth cvlface/pretrained_models/alignment/- Recognition models:
Conduct research using the Copy-Folder Method
mainFor face recognition research, the project recommends the Copy-Folder Method instead of relying solely on Git for experimental iterations. This allows you to run multiple parallel experiments independently and compare them easily using IDE folder comparison tools.
Workflow Steps:
- Initialize: Copy the
research/recognition/code/run_v1folder to a new directory named after your experiment (e.g.,new_loss_v1). - Modify: Apply your changes (e.g., a new loss function or architecture) within that specific folder.
- Version: Use semantic versioning for folder names (e.g.,
new_loss_v1,new_loss_v2) to track modifications. - Iterate: Repeat the process for each new experimental idea.
code/ run_v1 (default)/ ... new_loss_v1/ ... new_loss_v2/ ... new_architecture_v1/ ...- Initialize: Copy the
Configure environment variables in cvlface/.env
mainBefore running the toolkit, you must configure the environment variables in the
cvlface/.envfile. The following keys must be set:DATA_ROOT: The directory path where datasets will be stored.HF_TOKEN: Your Hugging Face authentication token.WANDB_TOKEN: Your Weights & Biases authentication token.
DATA_ROOT="path where datasets will be stored" HF_TOKEN="token for https://huggingface.co/" WANDB_TOKEN="token for https://wandb.ai/"