isarandi / metrabs

Estimate absolute 3D human poses from RGB images.
https://arxiv.org/abs/2007.07227
MIT License
470 stars 69 forks source link

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

Open 1165048017 opened 3 years ago

1165048017 commented 3 years ago

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 commented 3 years ago

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

Nick22ll commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 8 months ago

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