ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.46k stars 16.28k forks source link

tensorflow pb export where are the classes? #11646

Closed grexai closed 1 year ago

grexai commented 1 year ago

Search before asking

Question

Hi, I would like to create a tensorflow export for my model. It went well and actually i can retrieve the detections but i cannot find the classes. I have trained a well-working segmentation modell. Exported it with the following params: python export.py --weights path/to/mymodel/weights/best.pt --nms --include pb --img 1024 The After adding combined non max suppression I have four output identity tensors. The first contains the bbs with (100,4) dims which are fine and i validated the detections, then 2 other identities which are probably the scores, however hard to decide which is which. The last one is an integer per image. Okay the other outputs belongs to the proto masks so its irrelevant in this case. Has anyone succeded to get the classes from tf model

Thanks in advance image

Additional

No response

github-actions[bot] commented 1 year ago

👋 Hello @grexai, 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 commented 1 year ago

@grexai hello,

Thank you for using YOLOv5! It seems that you're facing an issue getting the classes from the tensorflow model after exporting. Unfortunately, we cannot help you with this as it goes beyond the scope of YOLOv5. However, we highly encourage you to take a look at the TensorFlow documentation and API reference for more information and support.

Best of luck with your project!

grexai commented 1 year ago

Thank you for the quick answer.

Well, I have checked the documentation, and based on it the 3rd tensor should be the right tensor to get the classes however these are full of floating point values that are smaller than 1. So it is unclear how they should be the classes and this is the reason why I think it is yolo related. image

glenn-jocher commented 1 year ago

@grexai you're welcome, glad to help. It looks like you've tried to use the 3rd tensor to get the classes, which according to the documentation should contain integers representing the class labels. However, you're seeing floating point values smaller than 1 instead.

While it's difficult to say definitively without more information, one possibility is that during export, the conversion from PyTorch to TensorFlow may have caused some unexpected behavior for this particular model. It's also possible that the issue is unrelated to YOLOv5 specifically.

To investigate further, we recommend verifying your model's behavior with an alternative setup, such as TensorFlow Serving or the TensorFlow runtime. You may also want to explore TensorFlow documentation and support resources to see if there are additional insights or solutions that can be applied.

grexai commented 1 year ago

The 3rd one is a floating point tensor not an integer. As a torch model the behaviour is fine.

glenn-jocher commented 1 year ago

@grexai thank you for your response. Based on your experience, it seems that the issue is related to the conversion from PyTorch to TensorFlow. As a PyTorch model, it behaves correctly, but the exported TensorFlow model is producing a floating-point tensor instead of integers.

This suggests that the issue is likely a result of the conversion process, rather than anything specific to YOLOv5. We recommend exploring alternative conversion methods or reaching out to the TensorFlow community for support in diagnosing the issue.

Best,

lucastack commented 1 year ago

Hello @grexai, are you using the detect.py script?

Best regards!

glenn-jocher commented 1 year ago

Hello @lucastack,

Thank you for reaching out to us. It looks like you're trying to get the class predictions from a TensorFlow exported model, but encountering unexpected floating point values instead of the expected integer class labels.

Can you please provide more information about the steps you're taking to export and use the model? It would also be helpful if you could share a code snippet of how you're accessing the output tensors to help us better understand the issue.

Best,

github-actions[bot] commented 1 year ago

👋 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 ⭐