peteryuX / retinaface-tf2

RetinaFace (Single-stage Dense Face Localisation in the Wild, 2019) implemented (ResNet50, MobileNetV2 trained on single GPU) in Tensorflow 2.0+. This is an unofficial implementation. With Colab.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can i saved pretrained model as "savedmodel" tensorflow format ?

jzoker opened this issue · comments

trying to load the weight from checkpoint and save entire model as ".savedmodel" format. Here is my code:

cfg_path = os.path.join(os.path.dirname(__file__), 'configs/retinaface_res50.yaml')
checkpoint_path = os.path.join(os.path.dirname(__file__), 'checkpoints/cpkt-81')
saved_path = os.path.join(os.path.dirname(__file__), 'retinaface_res50')


def main(_):
    cfg = load_yaml(cfg_path)
    model = RetinaFaceModel(cfg, training=True)
    model.summary()
    model.load_weights(checkpoint_path).expect_partial()
    model.save(saved_path)

it seem cant load the weights by load_weights():
image

So how do i save pretrained model as a file in tf2 format ?

Hi, Have you solved this problem now? I also encountered the problem of failing to load the weight.

I would also like to know. Face detection models in saved model format are rare

were you able to solve this?

You should load using checkpoint like in test.py and save as usual
image

@tucachmo2202 Thanks. Following this method I converted the model to savedModel format. I then converted the savedModel format to TensorFlow Lite (tflite). But Now using the tflite version I get 16800 anchor points (16800 for bbox, 16800 for landmarks and also for scores). How can convert these points to proper bounding box, landmarks and scores?

@fisakhan Hi,
I guess shape of output is 16800*16? So, if that is true, you may not use NMS for all that bbox. You can put NMS into network like origin model or use NMS with 16800 anchor you receive.

No, its (16800,2), (16800,4) and (16800,10), what is NMS?

No, its (16800,2), (16800,4) and (16800,10), what is NMS?

NMS is Non maximum suppression. You apply NMS for bbox to remove redundant or duplicate bbox (you will get indices then apply for landmarks too). And, if you don't modify the oringin model, I guess you are wrong at something because, it also has NMS (image below).
image

I was unable to convert this model to tflite using TFv2.2.0 due to NMS and other native Tensorflow operations.
Getting this error :
image

Has anyone figured out how to port RetinaFace to TensorFlow Lite?