StanislasBertrand / RetinaFace-tf2

RetinaFace (RetinaFace: Single-stage Dense Face Localisation in the Wild, published in 2019) reimplemented in Tensorflow 2.0, with pretrained weights available !
MIT License
258 stars 21 forks source link

tflite #17

Closed fisakhan closed 3 years ago

fisakhan commented 3 years ago

How can we convert this model into .h5 or savedmodel or tflite?

StanislasBertrand commented 3 years ago

Hi, The model is stored in the "model" attribute of the RetinaFace object, so you can try something like this : detector = RetinaFace(FLAGS.weights_path, FLAGS.use_gpu_nms, FLAGS.nms_thresh) model = detector.model model.save_weights("path_to_file.h5")

Let me know if it works

fisakhan commented 3 years ago

AttributeError: 'Function' object has no attribute 'save_weights'

StanislasBertrand commented 3 years ago

Ok try this code (taken from from retinaface.py):

from networks.retinaface_network import RetinaFaceNetwork model = RetinaFaceNetwork(model_weights).model model.save_weights("path_to_file.h5")

fisakhan commented 3 years ago

This code saved the model in .h5 format (I named it "rf.h5") having size of 118.7MB. But after trying to load the model using the following code, I received an error. loaded_model_from_h5 = tf.keras.models.load_model('rf.h5')

raise ValueError('No model found in config file.') ValueError: No model found in config file.

This https://github.com/keras-team/keras/issues/6937 might be the reason.

StanislasBertrand commented 3 years ago

Yes I think this is the issue, try using model.save() instead of save_weights() Sorry I dont have my laptop so I cant test myself at the moment