You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I 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?
What if you try to use the tflite model with tf-bodypix?
If you pass a file ending with .tflite to the load_model method, then it should use the tflite API.
You should also be able to use the CLI.
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).
Thanks for your response. Your answer really helps me. I need the location of each pose from this model. When I feed an image into it, the output result is a dictionary with these values: float_short_offsets, float_segments, float_part_heatmaps, float_long_offsets, float_heatmaps, MobilenetV1/displacement_fwd_2/BiasAdd, MobilenetV1/displacement_bwd_2/BiasAdd, and float_part_offsets. I can not figure out which ones of these values are corresponds to the poses locations.
I would say that implementing the pose detection isn't trivial. You can look at the related changes to this project to add support for it: https://github.com/de-code/python-tf-bodypix/pull/74/files
(Looking at the source code should also give clues as to what model outputs are relevant)
I would be hesitant though to re-implement the pose detection unless you really need to.
I don't know what you want to achieve. Can you not use tf-bodypix on the Raspberry Pi? (I must admit I haven't tried it myself)
If you are using a Python version of TensorFlow Lite, then we could work together on making tf-bodypix work with that
If you are not using Python TensorFlow Lite, but you do use Python to interpret the results, then we can work together on refactoring tf-bodypix to make it easier to re-use the code that interprets the results (e.g. in case some imports get in the way)
If you are not using Python at all, then I can only offer the code as a reference and perhaps debugging the Python version will help you to understand it better
I think the first suggestion is the best and can help other people. I try to make changes in tf-bodypix so that it can work with tflite model.
In the first step, I should figure out what is its output means. I would be grateful if you help me to understand that.
I think the first suggestion is the best and can help other people. I try to make changes in tf-bodypix so that it can work with tflite model. In the first step, I should figure out what is its output means. I would be grateful if you help me to understand that.
There is already TensorFlow Lite support, at least using the TensorFlow Lite provided via the full TensorFlow.
Hi again.
Following our previous conversations, I release the tflite inference from TensorFlow. It would be my pleasure to share my code with you and contribute to this project. If you are ok, please give me access to add a folder for tflite inference only using PIL, numpy, tflite, and cv2.
Thanks
Hi again. Following our previous conversations, I release the tflite inference from TensorFlow. It would be my pleasure to share my code with you and contribute to this project. If you are ok, please give me access to add a folder for tflite inference only using PIL, numpy, tflite, and cv2. Thanks
That is great news.
The best will be to fork the repo and submit a PR with the changes. It will give me a chance to review and test it.
Activity
de-code commentedon Nov 23, 2021
What if you try to use the
tflitemodel withtf-bodypix?If you pass a file ending with
.tfliteto theload_modelmethod, then it should use thetfliteAPI.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).
MrRiahi commentedon Nov 23, 2021
Thanks for your response. Your answer really helps me. I need the location of each pose from this model. When I feed an image into it, the output result is a dictionary with these values:
float_short_offsets,float_segments,float_part_heatmaps,float_long_offsets,float_heatmaps,MobilenetV1/displacement_fwd_2/BiasAdd,MobilenetV1/displacement_bwd_2/BiasAdd, andfloat_part_offsets. I can not figure out which ones of these values are corresponds to the poses locations.de-code commentedon Nov 23, 2021
I would say that implementing the pose detection isn't trivial. You can look at the related changes to this project to add support for it:
https://github.com/de-code/python-tf-bodypix/pull/74/files
(Looking at the source code should also give clues as to what model outputs are relevant)
I would be hesitant though to re-implement the pose detection unless you really need to.
I don't know what you want to achieve. Can you not use
tf-bodypixon the Raspberry Pi? (I must admit I haven't tried it myself)MrRiahi commentedon Nov 24, 2021
The reason I want to use the TensorFlow lite is that Tensorflow v2x is not supported for Raspberry pi 4.
de-code commentedon Nov 24, 2021
It seems there are non-official wheels to install the full TensorFlow v2.x. Perhaps something to try anyway. Or build and cross-compile from source.
When you are using TensorFlow Lite though, what API / language are you using? Are you using a Python API or do you implement it in C?
MrRiahi commentedon Nov 24, 2021
Exactly. I use python but if there are not no other solutions, I can switch to C.
de-code commentedon Nov 24, 2021
This is what I can suggest:
tf-bodypixwork with thattf-bodypixto make it easier to re-use the code that interprets the results (e.g. in case some imports get in the way)MrRiahi commentedon Nov 24, 2021
I think the first suggestion is the best and can help other people. I try to make changes in tf-bodypix so that it can work with tflite model.
In the first step, I should figure out what is its output means. I would be grateful if you help me to understand that.
de-code commentedon Nov 24, 2021
There is already TensorFlow Lite support, at least using the TensorFlow Lite provided via the full TensorFlow.
MrRiahi commentedon Dec 5, 2021
Hi again.
Following our previous conversations, I release the tflite inference from TensorFlow. It would be my pleasure to share my code with you and contribute to this project. If you are ok, please give me access to add a folder for tflite inference only using PIL, numpy, tflite, and cv2.
Thanks
de-code commentedon Dec 5, 2021
That is great news.
The best will be to fork the repo and submit a PR with the changes. It will give me a chance to review and test it.
MrRiahi commentedon Dec 5, 2021
Thanks. I will do it in the near future.
MrRiahi commentedon Dec 12, 2021
Hi again. I fork the repo and put my codes in the
bodypix_tflitefolder.de-code commentedon Dec 13, 2021
Great, thank you. Can you create a PR please?
MrRiahi commentedon Dec 15, 2021
I created a pull request in the past few days.