Convert model to tflite model
See original GitHub issueI want to run this code on raspberry pi 4. In the first step, I should convert this model to tflite model. I use the following link https://www.tensorflow.org/lite/convert/index to convert the model but it raises the following error.
OSError: SavedModel file does not exist at: ./models/mobilenet-float16-stride16/{saved_model.pbtxt|saved_model.pb}
I also use the following code for model conversion
python -m tf_bodypix \ convert-to-tflite \ --model-path \ "https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/075/model-stride16.json" \ --optimize \ --quantization-type=float16 \ --output-model-file "./mobilenet-float16-stride16.tflite"
it works and the model convert to tflite but when I want to use it in tensorflow lite based on this link https://www.tensorflow.org/lite/guide/inference, I found that the input model dimension is array([1, 1, 1, 3], dtype=int32). Can you help me to solve this problem?
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (15 by maintainers)
Top GitHub Comments
I created a pull request in the past few days.
What if you try to use the
tflite
model withtf-bodypix
? If you pass a file ending with.tflite
to theload_model
method, then it should use thetflite
API. You should also be able to use the CLI.You can find the implementation in the code: https://github.com/de-code/python-tf-bodypix/blob/v0.3.8/tf_bodypix/model.py#L455-L504
The ranks of the input shapes are not always the same, and sometimes it is a 4D tensor, sometimes a 3D tensor (depending on the conversion method). If it is a 4D tensor and you can simply resize the tensor to make it 4D. In that case the first dimension will typically be the batch size. The other feature of tflite or the model is that the width and height is dynamic. With tflite you need to resize the actual tensor (see linked code block).