Giter Site home page Giter Site logo

joonb14 / jhface Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 0.0 37.02 MB

Face Recognition training and testing framework with tensorflow 2.0 based on the well implemented arcface-tf2. Changes are added to provide tensorflow lite conversion, and provide additional backbones, loss functions.

Jupyter Notebook 99.70% Python 0.30%
tflite tensorflowlite tensorflow-lite python arcface tf2 tensorflow2 face-recognition face-recognition-python face-recognition-tensorflow

jhface's Introduction

JHFace

This project is based on the well implemented arcface-tf2. The things that rise error when converting the model to tflite was changed.

Training the Model

For preparing data, follow the instructions provided in data-preparing Then checkout the TensorFlow ArcFace.ipynb.

Backbones w/ ImageNet pretrained weights:

NasNet case, because of this issue, we manually download the weight file and explicitly load it in models.py file. We tried to provide pretrained weights for the MobileNet and EfficientNet models. However the official Keras implementations of the MobileNetV3 has built in preprocessing layers inside the model. Also this accounts to EfficientNet as well. So for the EfficientNet and EfficientNetLite, we used Weights Transfer.ipynb for extracting pretrained weights. To use the pretrained weights for NasNet, EfficientNet, EfficientNetLite please download the weights using this link. Then unzip it inside the path/to/JHFace/weights/ directory. All of the pretrained weights are provided by(or extracted from) tf.keras.applications

  • MobileNet
  • MobileNetV2
  • InceptionResNetV2
  • InceptionV3
  • ResNet50
  • ResNet50V2
  • ResNet101V2
  • NASNetLarge
  • NASNetMobile
  • Xception
  • MobileNetV3Large
  • MobileNetV3Small
  • EfficientNetLite0 ~ Lite6
  • EfficientNetB0 ~ B7
Backbones w/o ImageNet pretrained weights:

We implemented MnasNet models looking at the official code. If there's a bug, please tell us through the github issue page!

  • MnasNetA1
  • MnasNetB1
  • MnasNetSmall
Loss Function
Configuration

in the TensorFlow ArcFace.ipynb, we provided simple configuration values. To change the model backbone, just change the backbone_type parameter. To change the loss function, just change the head_type parameter.

### MS1M dataset

batch_size = 128 # Initially 128
input_size = 112
embd_shape = 512
head_type = 'ArcHead' # 'ArcHead', 'CosHead', 'SphereHead'
# Backbones w/ pretrained weights:
#     MobileNet, MobileNetV2, InceptionResNetV2, InceptionV3, ResNet50, ResNet50V2, ResNet101V2, NASNetLarge, NASNetMobile, Xception, MobileNetV3Large, MobileNetV3Small, EfficientNetLite0~6, EfficientNetB0~7
# Backbones w/o pretrained weights:
#      MnasNetA1, MnasNetB1, MnasNetSmall 
backbone_type = 'EfficientNetLite0' 
w_decay=5e-4
num_classes = 85742 
dataset_len = 5822653 
if head_type == 'SphereHead':
    base_lr = 0.01 
    margin = 1.35
    logist_scale = 30.0 
elif head_type == 'CosHead':
    base_lr = 0.01 
    margin=0.35
    logist_scale=64
elif head_type == 'ArcHead':
    base_lr = 0.01 
    margin=0.5
    logist_scale=64
else:
    base_lr = 0.01 # initially 0.01
epochs = 20
save_steps = 1000
train_size = int(0.8 * dataset_len)
print(train_size)
steps_per_epoch = train_size // batch_size
print(steps_per_epoch)
val_size = dataset_len - train_size
print(val_size)
validation_steps = val_size // batch_size
print(validation_steps)
steps = 1
is_ccrop=False
binary_img=True
is_Adam = False

Converting the Model to TensorFlow Lite

checkout the TFLite conversion.ipynb. Int8 quantization is supported, we checked with MobileNetV2 and EfficientNet-lite0.

For Face Verification

We downloaded the testing dataset from here. With the data use the verification.ipynb for verification test.

For Face Identificaiton

checkout the Face Identification with Centroid Vector.ipynb.

jhface's People

Contributors

hhlee07 avatar joonb14 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jhface's Issues

Dataset format

Hello,
Thanks for this good work.
Does one have to convert the dataset to tfrecord.
Or will it work by just pointing to directories.
Thanks

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.