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

*.tflite export #453

Closed
Mostafa-elgendy opened this issue Jul 20, 2020 · 15 comments
Closed

*.tflite export #453

Mostafa-elgendy opened this issue Jul 20, 2020 · 15 comments
Labels
question Further information is requested Stale

Comments

@Mostafa-elgendy
Copy link

❔Question

Additional context

I have followed the instruction to train your model on a custom dataset and got "last_yolov5s_results.pt" this weight file.
My question is how to use this file to run the yolov5 model on an android device?
for example how to convert it to tflite

@Mostafa-elgendy Mostafa-elgendy added the question Further information is requested label Jul 20, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Jul 20, 2020

Hello @Mostafa-elgendy, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For more information please visit https://www.ultralytics.com.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 20, 2020

@Mostafa-elgendy the export pipeline is pytorch to onnx to tflite. You can export to onnx following the export tutorial: https://docs.ultralytics.com/yolov5

@bartvollebregt
Copy link

bartvollebregt commented Aug 13, 2020

I tried to convert the ONNX file to TFlite.
Using converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
the org.tensorflow.lite.Interpreter function throws The TensorFlow library was compiled to use SSE instructions, but these aren't available on your machine.. (On a Pixel XL emulator running API 29).

When converting using converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS], it will throw an error:
error: 'tf.AddV2' op is neither a custom op nor a flex op

These issues seem related:

@glenn-jocher glenn-jocher changed the title Test on android mobile device *.tflite export Aug 13, 2020
@glenn-jocher
Copy link
Member

@bartvollebregt suggest you raise an issue on the relevant repo, and supply them code to reproduce.

@zldrobit
Copy link
Contributor

@bartvollebregt I wrote a PR to convert yolov5 to TFLite model with TensorFlow 2.3, try using #959 if you are interested.

@BernardinD
Copy link

BernardinD commented Sep 14, 2020

@zldrobit do you have a script of running the tflite graph that you could also share?

@BernardinD
Copy link

BernardinD commented Sep 14, 2020

@zldrobit Did you get the ValueError: Didn't find op for builtin opcode 'RESIZE_NEAREST_NEIGHBOR' version '3' issue?

How did you get around it?

@zldrobit
Copy link
Contributor

@BernardinD I ran into this problem when I use different TF versions for converting models and inference.
Which version of TF are you using?
The only TF version tested successfully with TFLite is 2.3 for the PR.

@BernardinD
Copy link

@zldrobit I used 1.15.3 in the hopes to avoid having to update my edgetpu version

@zldrobit
Copy link
Contributor

@BernardinD , I haven't used an edgetpu. I fail to infer TFLite model on TF 1.15, which is converted with TF 2.3.
With TF 1.15, saved_model and graph_def formats can be correctly inferred.
Which format are you using, TF saved_model, graph_def or TFLite?

@BernardinD
Copy link

BernardinD commented Sep 15, 2020

@BernardinD , I haven't used an edgetpu. I fail to infer TFLite model on TF 1.15, which is converted with TF 2.3.
With TF 1.15, saved_model and graph_def formats can be correctly inferred.
Which format are you using, TF saved_model, graph_def or TFLite?

I tried running the TF 2.3 tflite model on TF 1.x and also tried running the TF 1.15.3 tflite model using your detect script script and got the same op error with both

Update: turns out I was using the TF 2.3 graph in both attempt. I falsely assumed your conversion script overwrote the previous file but it actually threw an error during the tflite conversion due to fact that TF 1.15.3 doesn't have the from_keras_model function for the TFLiteConverter but instead the from_keras_model_file

Update: After editing your script to include tf.lite.TFLiteConverter.from_keras_model_file(path) I was able to export the tflite graph but when I try to run its detection I get:

RuntimeError: tensorflow/lite/kernels/strided_slice.cc ellipsis_mask is not implemented yet.Node number 211 (STRIDED_SLICE) failed to prepare.

@zldrobit
Copy link
Contributor

@BernardinD I think this may be a bug of TFLite 1.15.
I recommend you use TFLite 2.3 because TFLite 2.0, 2.1 and 2.2 GPU deletegates produce incorrect results for yolov3 (tensorflow/tensorflow#40613).

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@lijianyu1985
Copy link

@zldrobit Did you get the ValueError: Didn't find op for builtin opcode 'RESIZE_NEAREST_NEIGHBOR' version '3' issue?

How did you get around it?

did you fix this error?

@zldrobit
Copy link
Contributor

@lijianyu1985 We have fixed this problem long ago. Plz use the latest YOLOv5 v6.1 version and try again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

6 participants