-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot parse file b'/content/drive/MyDrive/MobileFaceNet/MobileFaceNet_TF-master/arch/pretrained_model/saved_model.pb': Error parsing message. #73
Comments
It's not possible to load the saved model to a Keras model. Tensorflow 2 changes relative to TF 1 are significant and Keras layers differ from the slim layers used in the sirius model. To load the saved model you must use Tensorflow 1.x with code similar to what you see in the sirius project. Once the graph/ckpt is loaded as a graph you can write out an hdf5 weights file with the help of h5py. The weights file can be loaded into a Keras model. However, you have to code a Keras model definition from scratch to exactly match the sirius definition in order to use the weights file. There is no converter that I could find. There are a number of Keras implementations of MobileFaceNet available, but they're not exact matches to the sirius model and would not be able to successfully load the weights file produced from the sirius ckpt. Probably the most sensible option is to create or find a Keras model of MobileFaceNet and then do the training all over again from the same dataset used by sirius. I didn't want to do this because of the potential time/expense required. So as an exercise I created the weights file from the sirius ckpt, created a matching Keras model, loaded the weights and then converted the Keras model to a tflite model to test it. The resulting model works, but doesn't seem to have the same level of accuracy as the original sirius tflite model. I suspect this is due to subtle differences between slim layers and corresponding Keras layers. There's also a custom prelu layer used in the sirius model that I replaced with a standard Keras PreLU layer. I suppose any or all of those differences could be affecting model accuracy. |
hi @jmattioni, can you share this modified keras implementation and the weights file that you created? |
It’s been quite a while since I worked with this model. I was able to find my latest Google Colab notebook with the recoded Keras model. Here’s a link to it: https://colab.research.google.com/drive/13ma9gXnPryeciAD6QFYLS9tjkETTvnh_?usp=sharing The blocks in the notebook have to be manually executed more or less in order. Sorry, there are comments but there’s no specific instructions. Blocks that start with a comment that contains “NOPE!” were NOT used in the final result. Don't run those. I don’t seem to have the original weights for the MobileFaceNet model. But, I believe the original MobileFaceNet weights are out there and should load into the Keras model built by the above notebook. In my application I refined the base MobileFaceNet model by further training it with cat face images. The Keras model was then converted to TFLite to run on an Android phone. The app was then used to recognize specific cats. Hope this helps! |
Just found what I believe to be the original MobileFaceNet weights. |
Thanks a lot @jmattioni! |
@jmattioni sorry to bother you again but do you have some insight on how to convert the frozen model (.pb file) to compatible .h5 keras file? I've searched to do this in several different ways but no one worked and seems like you have done this succesfully. |
I believe this is the original weights file: |
I am trying to load the pretrained_model into a keras object by using tf.keras.models.load_model(). I've already renamed the model to saved_model.pb . However, I met this error which said:
How can I load and use the model (I need to use .fit() and .predict() methods).
Thank you !
I am using tensorflow 2.3.0
The text was updated successfully, but these errors were encountered: