Skip to content
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

If it is possible to convert the saved model to tflite model? #14

Open
1165048017 opened this issue Aug 17, 2021 · 7 comments
Open

If it is possible to convert the saved model to tflite model? #14

1165048017 opened this issue Aug 17, 2021 · 7 comments

Comments

@1165048017
Copy link

I downloaded the single person from here

https://omnomnom.vision.rwth-aachen.de/data/metrabs/metrabs_singleperson_smpl.zip 

And want to convert the saved model to tflite model by tflite converter :

model = tf.saved_model.load("./metrabs_singleperson_smpl/")
converter = tf.lite.TFLiteConverter.from_concrete_functions(model.__call__.concrete_functions)
tfmodel = converter.convert()

then it crashed and the log is

InvalidArgumentError: Input 2 of node StatefulPartitionedCall was passed float from unknown:0 incompatible with expected resource.

Did I miss something while converting?
Thanks for you good job ~~~

@isarandi
Copy link
Owner

I tried this conversion briefly as well but apparently some operation is not compatible with tflite. I'll keep this open for now.

@Nick22ll
Copy link

Nick22ll commented Dec 1, 2021

I tried this conversion briefly as well but apparently some operation is not compatible with tflite. I'll keep this open for now.

With the new models version (TF2), the mentioned operations are still incompatible?

I'm new to this world and I don't understand much but I tried to convert like this:
converter = tf.lite.TFLiteConverter.from_saved_model("./models/metrabs_eff2l_y4")
and it raised an error:
ValueError: Only support at least one signature key.
It seems that there isn't any signature but I checked the code (src/models/metrabs.py) and I saw a signature( and it isn't t the only one).
I'm missing something or it is an intentional behavior?
Thanks for you hard work!

@isarandi
Copy link
Owner

isarandi commented Dec 1, 2021

Can you let me know what your use case would be? The big model needs a powerful GPU anyway, so it's not like you can deploy it easily on some lightweight embedded device. I'll try looking into it though.

@Nick22ll
Copy link

Nick22ll commented Dec 1, 2021

I'm writing an android app to evaluate pose differences for a university project. I posted the previous code as example but this error came out also with using the MobileNet model.
The code:
converter = tf.lite.TFLiteConverter.from_saved_model("./models/metrabs_mob3l_y4t")
the error:
ValueError: Only support at least one signature key.

@tobibaum
Copy link

@Nick22ll
you could try to save the model with a different signature. I haven't tested this, but it might be a step in the right direction. lmk!

import tensorflow as tf
model_folder = 'models/metrabs_eff2s_y4/'
out_fold='models/eff2s_y4_short_sig'
model = tf.saved_model.load(model_folder)

@tf.function()
def my_predict(my_prediction_inputs, **kwargs):
    prediction = model.detect_poses(my_prediction_inputs)
    return {"prediction": prediction['poses3d']}

my_signatures = my_predict.get_concrete_function(
   my_prediction_inputs=tf.TensorSpec([None,None, 3], dtype=tf.dtypes.uint8, name="image"))

tf.saved_model.save(model, out_fold, signatures=my_signatures)

@Nick22ll
Copy link

@tobibaum thank you very much!
In the end I changed my mind... I decided to develop a WebApp and run the models in a python server.
Maybe in the future I'll try your idea: I have plenty of projects in mind!

@TheSav1101
Copy link

Since this is still open I will confirm that the method that @tobibaum proposed is not working because of two operators that are not supported by tflite (Cross and ResizeArea) that would need to be implemented as custom operators.

I think that there is a way to overcome ResizeArea by fixing the input size of the signature and modifying the parameters used in the prediction, but I could not figure out a way to get around Cross, if you have any idea I am open to suggeestions :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants