• Stars
    star
    177
  • Rank 215,985 (Top 5 %)
  • Language
    Python
  • Created over 6 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

center loss for face recognition

center-loss.pytorch

Center loss implementation for face recognition in pytorch. Paper at: A Discriminative Feature Learning Approach for Deep Face Recognition

Requirements

  • Python 3.6
  • Pytorch 0.4

Usage

Training No need to download anything. The following command will create directorys and download everything automatically.

# For quick reference and small GPU ram
python3 main.py --arch resnet18 --batch_size 64 --epochs 50

# For a more solid model
python3 main.py

# or
python3 main.py --arch resnet50 --batch_size 256 --epochs 150

Evaluation

python3 main.py --evaluate ./logs/models/epoch_xx.pth.tar

# Model accuracy is 0.961722195148468
# ROC curve generated at /home/louis/center-loss.pytorch/logs/roc.png

More Options

usage: main.py [-h] [--batch_size N] [--log_dir LOG_DIR] [--epochs N]
               [--lr LR] [--arch ARCH] [--resume RESUME]
               [--dataset_dir DATASET_DIR] [--weights WEIGHTS]
               [--evaluate EVALUATE] [--pairs PAIRS] [--roc ROC]
               [--verify-model VERIFY_MODEL] [--verify-images VERIFY_IMAGES]

center loss example

optional arguments:
  -h, --help            show this help message and exit
  --batch_size N        input batch size for training (default: 256)
  --log_dir LOG_DIR     log directory
  --epochs N            number of epochs to train (default: 100)
  --lr LR               learning rate (default: 0.001)
  --arch ARCH           network arch to use, support resnet18 and resnet50
                        (default: resnet50)
  --resume RESUME       model path to the resume training
  --dataset_dir DATASET_DIR
                        directory with lfw dataset (default:
                        $HOME/datasets/lfw)
  --weights WEIGHTS     pretrained weights to load default:
                        ($LOG_DIR/resnet18.pth)
  --evaluate EVALUATE   evaluate specified model on lfw dataset
  --pairs PAIRS         path of pairs.txt (default: $DATASET_DIR/pairs.txt)
  --roc ROC             path of roc.png to generated (default:
                        $DATASET_DIR/roc.png)
  --verify-model VERIFY_MODEL
                        verify 2 images of face belong to one person,the param
                        is the model to use
  --verify-images VERIFY_IMAGES
                        verify 2 images of face belong to one person,split
                        image pathes by comma

Experiments

Trained a model with default configuration(resnet50 for 100 epochs). The model can be downloaded from Baidu Yun or Google Drive.

Results shown as follows:

python main.py --evaluate logs/models/epoch_100.pth.tar --batch_size 128

Model accuracy is 0.9628332853317261
ROC curve generated at /home/louis/center-loss.pytorch/logs/roc.png

Experiments with MNIST dataset

softmax only

softmax + center loss

Random People Verification

2 images of Obama and 2 images of Trump. Verify 4 pairs together using the model.

➜ python main.py --verify-model logs/models/epoch_100.pth.tar --verify-images images/obama_a.png,images/obama_b.png
distance: 0.9222122430801392
➜ python main.py --verify-model logs/models/epoch_100.pth.tar --verify-images images/trump_a.png,images/trump_b.png
distance: 0.8140196800231934
➜ python main.py --verify-model logs/models/epoch_100.pth.tar --verify-images images/obama_a.png,images/trump_a.png
distance: 1.2879283428192139
➜ python main.py --verify-model logs/models/epoch_100.pth.tar --verify-images images/obama_b.png,images/trump_b.png
distance: 1.26639723777771

We can see that threshold of 1.1 will perfectly seperate them.

Due to the small dataset, this model is just for quick example reference. If one wants to use in production, change the feature extract network and train on a larger dataset.

More Repositories

1

minetorch

Build deep learning applications in a new and easy way.
Python
239
star
2

sfd.pytorch

S3FD: single shot face detector in pytorch
Jupyter Notebook
114
star
3

torchscript-demos

A brief of TorchScript by MNIST
C++
105
star
4

gradio-log

A Gradio component designed to continuously show any logs.
Python
25
star
5

dsb

kaggle 2018 data science bowl competition
Python
24
star
6

exhaustive-weighted-random-sampler

The missing distributed weighted random sampler for PyTorch
Python
24
star
7

reef-solution

reef-solution for upload
Python
23
star
8

ai4code

ai4code competition source code
Python
18
star
9

pytorch-tao

tao for machine learning
Python
12
star
10

focal-loss.pytorch

Focal loss implemention by PyTorch
Python
11
star
11

BiSeNet.pytorch

BiSeNet in pytorch
Python
10
star
12

nvjpeg2k-python

NVJPEG2K python binding
C++
9
star
13

rsna-2022-public

RSNA Screening Mammography Breast Cancer Detection 26 th source code
Python
6
star
14

torch-serve-mnist

torch-serve-mnist example
Python
4
star
15

featurize-doc

document of featurize
Ruby
3
star
16

gislr-live

Live Demo of Google - Isolated Sign Language Recognition
JavaScript
3
star
17

pytorch-tricks

Jupyter Notebook
3
star
18

featurize-comfyui

Python
1
star
19

hcho-bill

Jupyter Notebook
1
star
20

tornado-resource-handler

tornado resource handler
Python
1
star
21

collector-go

log collector in go
Go
1
star
22

maskrcnn.pytorch

mask rcnn implemented by pytorch
Python
1
star
23

aio-scheduler

This is async io scheduler based on redis
Python
1
star
24

voc2012-dataset.torch

Pytorch Dataset and other utils for VOC2012 dataset
Jupyter Notebook
1
star
25

featurize-tensorboard

在 Featurize 中使用 TensorBoard
Python
1
star
26

simple-uploader

Resumable file upload service
Go
1
star