Skip to content

godofpdog/MobileFaceNet_keras

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MobileFaceNet with Arc-Face Loss


Requirments

numpy 1.15.1
keras 2.2.4
tensorflow-gpu 1.9.0
opencv-python 3.4.3.18

Training

python train_MobileFaceNet.py train_directory data_directory pairs_filename  <--optional_arguments>

Arguments

  • Data Generator
  • Model
  • Training
  • Eveluattion

Data Generator

  • You can define your own data generator in src/data_generators.py
Argument Description type Default
train_directory Training dataset directory str
valid_directory Validation dataset directory str
batch_size Batch size of generator. int 200
aug_freq Frequency of data augmentation. float 0.5
image_size Image size same as model input size. int 112
shuffle Shuffle on end of epoch. bool True

Model

Argument Description type Default
expansion_ratio Expansion ratio of res_block. int 6
embedding_dim Embedding Dimension. int 256
loss_scale Scale parameter of arc-face loss. int 64
loss_margin Angular margin of arc-face loss. float 0.5

Training

Argument Description type Default
pretrained_model Pre-trained model filename. str None
save_model_directory Directory to save model str weights/
checkpoint_epochs Save checkpoint every n epochs. int 5
epochs Max number of training epochs int 300
valid_split_ratio Split ratio of validation set float 0.1
evaluate_epochs Evaluate model every n epochs int 5

Evaluation

Argument Description type Default
data_directory Evaluation dataset directory. str
pairs_filename Pairs file name str
sample_type

Sample type of the task.

0 : balance pos/neg

1 : sample by person and img per person.

0

or

1

0
repeat_times Repeat times of generation, this argument only be used when sample type is 0. int 10
num_person Number of person to sample, this argument only be used when sample type is 1. int 10
num_sample Number of sample per person, this argument only be used when sample type is 1. int 20
far_target Target FAR(False Accept Rate) float 1e-2

GPU

Argument Description type Default
gpu Specify a GPU. str '1'

infer example

import cv2 
import matplotlib.pyplot as plt
from src.build_model import ArcFaceLossLayer, dummy_loss
from src.feature_extractor import FeatureExtractor

# load model
model_path = 'weights/weights.h5'
fe = FeatureExtractor(model_path, num_classes=24)

# load image and resize to model input size 
path = 'images.jpg'
img = cv2.imread(path)[:, :, ::-1]
img_resize = cv2.resize(img, (112, 112))

# infer 
emb = fe.infer(img_resize)
emb.shape
>> (1, 512)

Reference

ArcFace : https://arxiv.org/abs/1801.07698\ MobileFaceNet : https://arxiv.org/abs/1804.07573

About

This is a keras implementation of MobileFaceNets architecture as described in the paper "MobileFaceNets: Efficient CNNs for Accurate Real-Time Face Verification on Mobile Devices"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages