This project is based on the well implemented arcface-tf2. The things that rise error when converting the model to tflite was changed.
For preparing data, follow the instructions provided in data-preparing Then checkout the TensorFlow ArcFace.ipynb.
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
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
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 = Falsecheckout the TFLite conversion.ipynb. Int8 quantization is supported, we checked with MobileNetV2 and EfficientNet-lite0.
We downloaded the testing dataset from here. With the data use the verification.ipynb for verification test.
checkout the Face Identification with Centroid Vector.ipynb.