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

convert to tflite #11555

Closed
1 task done
nurulamelia2 opened this issue May 20, 2023 · 15 comments
Closed
1 task done

convert to tflite #11555

nurulamelia2 opened this issue May 20, 2023 · 15 comments
Labels
question Further information is requested Stale Stale and schedule for closing soon

Comments

@nurulamelia2
Copy link

Search before asking

Question

hello, I want to ask. How do you convert best.pt to tflite using yolov5 on google collab? I've tried converting, but after running the result is different.

Additional

No response

@nurulamelia2 nurulamelia2 added the question Further information is requested label May 20, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2023

👋 Hello @nurulamelia2, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@nurulamelia2 hi there! Thank you for your interest in YOLOv5. To convert best.pt to tflite, you can use the export.py script with the --weights argument to specify the path to your .pt file and --train to specify the name of the exported .tflite file. Here is an example command to export to tflite:

!python export.py --weights /path/to/best.pt --img 640 --batch 1 --train --name yolov5s-export

After running this command, you will have a yolov5s-export.tflite file in the yolov5s-export folder. Please note that this is just a suggested command, and you might need to adjust the arguments based on your specific use case. Let me know if you have any other questions.

@nurulamelia2
Copy link
Author

sorry I want to ask again, after I did a run like this
#!python export.py --weights runs/train/yolov5s_results/weights/best.pt --include tflite
there is indeed a .tflite file but it is not my model. My model is sign language while when I try to check the results the file is a model that shows object detection 'car', and others. While my best.pt model is correct located here runs/train/yolov5s_results/weights/best.pt. What is the solution?

I tried !python export.py --weights runs/train/yolov5s_results/weights/best.pt --img 640 --batch 16 --train --name yolov5s_results, but it doesn't work either.

Can you provide a solution for me? thank you in advance

@nurulamelia2
Copy link
Author

when testing with best.pt the results obtained are correct, namely sign language detection, but after converting to .tflite form with the command as above, the results obtained are very much different, the detection issued by cars, humans and others. am I doing the conversion wrong sir?

@glenn-jocher
Copy link
Member

@nurulamelia2 hello! It's possible that the conversion to tflite did not work as expected. Can you try specifying the input and output shapes of the model explicitly using --input_shape and --output_shape arguments when running export.py? This is because sometimes the default shapes inferred by export.py do not match the actual shapes of the model resulting in unpredictable output results.

You can run the following command to specify the input and output shapes of the model explicitly:

!python export.py --weights /path/to/best.pt --img 640 --batch 1 --train --name yolov5s-export --include tflite --input_shape 1,3,640,640 --output_shape 1,25200,85

Replace /path/to/best.pt with the actual path to your best.pt file and adjust the --img and --batch arguments as needed for your use case. Also, please note that the --input_shape and --output_shape arguments depend on the architecture of the YOLOv5 model you're using and may need to be adjusted accordingly.

Let me know if this helps or if you have any other questions.

@nurulamelia2
Copy link
Author

can you help me by looking at my code? i have tried but it still doesn't work.

https://colab.research.google.com/drive/1LpPKLf49s46R8O19JzmAgbLyJpqt8Y8x?usp=sharing

I'm really confused because I tried several times but the problem was not solved. This assignment is for tomorrow, and I'm still struggling. thank you sir

@glenn-jocher
Copy link
Member

@nurulamelia2 hello, I understand that you are having issues with your code and are working with a deadline. However, in order to help you effectively, we need some more information on what exactly is not working. Can you please provide more details on what issue you are facing with your code?

In the meantime, I suggest double-checking your code for any syntax errors, ensuring that all necessary libraries are installed and imported correctly, and verifying that your input data is in the correct format for the YOLOv5 model.

Also, keep in mind that it's often helpful to approach issues step-by-step and try to isolate the problem. In this case, you could try testing your code on a smaller dataset or verifying that the model architecture itself is working correctly.

Please provide more details on the specific issue you are having so that we can best assist you in resolving the problem. Good luck and we look forward to hearing back from you!

@nurulamelia2
Copy link
Author

I want to ask again, because I'm still curious. is the cause because the custom data is not read and the coco data is read, so when converting an error occurs. Here is the information when converting

export: data=data/coco128.yaml, weights=['/content/yolov5/runs/train/yolov5s_results/weights/best.pt']

is that where the problem lies?

@glenn-jocher
Copy link
Member

@nurulamelia2 hello and thank you for reaching out to us. It's possible that the issue is caused by the fact that the exported model is still using the data/coco128.yaml file during the conversion process instead of your custom dataset. When exporting to tflite, make sure to specify the --data argument with the path to your custom .yaml file (e.g. --data /path/to/your/custom.yaml).

Also, double-check that your custom .yaml file is correctly formatted with the correct class names and their respective IDs. Issues with the .yaml file can also cause unpredictable results during model training and inference.

Please try this and let us know if the issue persists or if you have any other questions. Thank you.

@nurulamelia2
Copy link
Author

problem solved, thank you very much. Can this .tflite model be deployed using kotlin programming language?

@github-actions
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Jul 21, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2023
@glenn-jocher
Copy link
Member

@nurulamelia2 absolutely! You can deploy the .tflite model using Kotlin or any other programming language that supports TensorFlow Lite. The TensorFlow Lite Android Support Library provides a convenient way to integrate tflite models into Android apps, including those developed in Kotlin.

You can find detailed documentation and examples on how to use TensorFlow Lite models in Android apps in the official TensorFlow Lite documentation.

If you encounter any hurdles during this process, feel free to reach out to us for further assistance. Good luck with your deployment!

@ANIS-AK
Copy link

ANIS-AK commented Dec 30, 2024

@nurulamelia2 hello and thank you for reaching out to us. It's possible that the issue is caused by the fact that the exported model is still using the data/coco128.yaml file during the conversion process instead of your custom dataset. When exporting to tflite, make sure to specify the --data argument with the path to your custom .yaml file (e.g. --data /path/to/your/custom.yaml).

Also, double-check that your custom .yaml file is correctly formatted with the correct class names and their respective IDs. Issues with the .yaml file can also cause unpredictable results during model training and inference.

Please try this and let us know if the issue persists or if you have any other questions. Thank you.

i have the same issue , i trained a yolov5 model to detect traffic lights and i tested the best.pt model the results are great , but when i converted it to tflite and tested it it's detecting all traffic lights as red light , i also specified --data with the path to my custom .yaml file but still the same issue , any suggestions ?
thank u

@ANIS-AK
Copy link

ANIS-AK commented Dec 30, 2024

Search before asking

Question

hello, I want to ask. How do you convert best.pt to tflite using yolov5 on google collab? I've tried converting, but after running the result is different.

Additional

_No respon

problem solved, thank you very much. Can this .tflite model be deployed using kotlin programming language?

how the problem was solved?

@pderrenger
Copy link
Member

Hello, it's great to hear your issue was resolved! For others experiencing similar challenges, could you please share the steps or adjustments you made to solve the problem? This would be helpful for the YOLO community. Thank you!

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 Stale and schedule for closing soon
Projects
None yet
Development

No branches or pull requests

4 participants