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

fix tf conversion in new v6 models #5153

Merged
merged 2 commits into from
Oct 12, 2021
Merged

fix tf conversion in new v6 models #5153

merged 2 commits into from
Oct 12, 2021

Conversation

YoniChechik
Copy link
Contributor

@YoniChechik YoniChechik commented Oct 12, 2021

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Integration of TFSPPF, a new TensorFlow spatial pyramid pooling-fast layer, into the YOLOv5 architecture.

πŸ“Š Key Changes

  • πŸ”§ Added the TFSPPF class to the TensorFlow model file, providing a new layer for spatial pyramid pooling with a fast implementation.
  • πŸ› οΈ Updated the parse_model function to include the new SPPF layer when constructing models.
  • πŸ’Ό Rearranged the import statements in models.tf.py to include the newly added SPPF alongside other common model components.

🎯 Purpose & Impact

  • πŸš€ The new TFSPPF layer is designed to improve model performance by providing a more efficient way to handle spatial data.
  • πŸ†• By integrating this layer into YOLOv5's TensorFlow implementation, developers and users can take advantage of enhanced object detection capabilities.
  • πŸ” The potential impact includes faster inference times and possibly improved accuracy, benefiting a wide range of applications from autonomous driving to security surveillance.

@glenn-jocher glenn-jocher linked an issue Oct 12, 2021 that may be closed by this pull request
@glenn-jocher glenn-jocher changed the title fix tf conversion in new v6 (#5147) fix tf conversion in new v6 models Oct 12, 2021
@glenn-jocher glenn-jocher merged commit 34da872 into ultralytics:master Oct 12, 2021
@glenn-jocher
Copy link
Member

@YoniChechik PR is merged. Thank you for your contributions to YOLOv5 πŸš€ and Vision AI ⭐

@rahuja23
Copy link

When I am exporting a custom trained model into tflite and then loading it , I am getting the following error:
Model provided has model identifier '
Any helps or suggestions what can be done?

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 14, 2021

@rahuja23 πŸ‘‹ hi, thanks for letting us know about this possible problem with YOLOv5 πŸš€. We've created a few short guidelines below to help users provide what we need in order to get started investigating a possible problem.

How to create a Minimal, Reproducible Example

When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:

  • βœ… Minimal – Use as little code as possible that still produces the same problem
  • βœ… Complete – Provide all parts someone else needs to reproduce your problem in the question itself
  • βœ… Reproducible – Test the code you're about to provide to make sure it reproduces the problem

In addition to the above requirements, for Ultralytics to provide assistance your code should be:

  • βœ… Current – Verify that your code is up-to-date with current GitHub master, and if necessary git pull or git clone a new copy to ensure your problem has not already been resolved by previous commits.
  • βœ… Unmodified – Your problem must be reproducible without any modifications to the codebase in this repository. Ultralytics does not provide support for custom code ⚠️.

If you believe your problem meets all of the above criteria, please close this issue and raise a new one using the πŸ› Bug Report template and providing a minimum reproducible example to help us better understand and diagnose your problem.

Thank you! πŸ˜ƒ

@rahuja23
Copy link

torch - 1.9.1
torchvision - 0.10.1
tensorflow- 2.6.0
I cloned the recent repo and trained the model on cloud using single GPU instance and when trying to convert the model with the latest export.py I am getting the following exception:
[34mοΏ½[1mTensorFlow saved_model:οΏ½[0m export failure: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 15, 2021

@rahuja23 your error is not reproducible. Training and export to TFLite operates correctly.

# Train YOLOv5s on COCO128 for 3 epochs
!python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --cache

# Export to TFLite, SUCCESS
!python export.py --weights runs/train/exp/weights/best.pt --include tflite

Screen Shot 2021-10-15 at 12 09 23 PM

How to create a Minimal, Reproducible Example

When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:

  • βœ… Minimal – Use as little code as possible that still produces the same problem
  • βœ… Complete – Provide all parts someone else needs to reproduce your problem in the question itself
  • βœ… Reproducible – Test the code you're about to provide to make sure it reproduces the problem

In addition to the above requirements, for Ultralytics to provide assistance your code should be:

  • βœ… Current – Verify that your code is up-to-date with current GitHub master, and if necessary git pull or git clone a new copy to ensure your problem has not already been resolved by previous commits.
  • βœ… Unmodified – Your problem must be reproducible without any modifications to the codebase in this repository. Ultralytics does not provide support for custom code ⚠️.

If you believe your problem meets all of the above criteria, please close this issue and raise a new one using the πŸ› Bug Report template and providing a minimum reproducible example to help us better understand and diagnose your problem.

Thank you! πŸ˜ƒ

@rahuja23
Copy link

Ok I figured it out I was setting the device parameter in export file as well to CUDA, if we leave it to default it works. Thanks for the new push guys πŸ‘πŸ»

BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* fix `tf` conversion in new v6 (ultralytics#5147)

* sort imports

Co-authored-by: Glenn Jocher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't build TF saved_model or tflite with new v6
3 participants