Face recognition in PyTorch.
Create an environment (Python 3.10):
conda create -n face-recognition python=3.10Install dependencies:
-
For CPU:
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu
-
For AMD GPU (for Windows users):
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu pip3 install torch-directml
-
For NVIDIA GPU:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cuxxx
pip install opencv-python richClone this repository:
git clone https://github.com/MarkIvory2973/face-recognition.gitcd face-recognition
python src/main.py train -d E:/Datasets -c ./checkpoints -e 40 -r 0.02 -s 16 -g 0.94
python src/main.py register -i 0 -c ./checkpoints -n Guest01
python src/main.py verify -i 0 -d E:/Datasets -c ./checkpoints -n Guest01Train mode:
| Parameter | Required | Default | Description |
|---|---|---|---|
| --datasets-root,-d | ✓ | - | Datasets root |
| --checkpoints-root,-c | - | ./checkpoints | Checkpoints root |
| --total-epoch,-e | - | 100 | Total epoch |
| --learning-rate,-r | - | 0.02 | Learning rate |
| --batch-size,-s | - | 16 | Batch size |
| --gamma,-g | - | 0.98 | The gamma of ExponentialLR |
Register mode:
| Parameter | Required | Default | Description |
|---|---|---|---|
| --camera-id,-i | - | 0 | Camera ID |
| --checkpoints-path,-c | - | ./checkpoints | Checkpoints path |
| --username,-n | ✓ | - | Username |
Verify mode:
| Parameter | Required | Default | Description |
|---|---|---|---|
| --camera-id,-i | - | 0 | Camera ID |
| --datasets-root,-d | ✓ | - | Datasets root |
| --checkpoints-path,-c | - | ./checkpoints | Checkpoints path |
| --username,-n | ✓ | - | Username |
⚠ The metrics in checkpoint.N.pth are based on the output of each 16 batch, so their Accuracy may be not correct enough (lower than actual).
I tested again with batch_size=1. Here is the result of checkpoint.best.pth (checkpoint.100.pth):
| Accuracy (%) | |
|---|---|
| LFW | 94.03 |