ultralytics / yolov5

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

How to access all the detection that have been made by the algorithm before the final results #11764

Closed ibou810 closed 1 year ago

ibou810 commented 1 year ago

Search before asking

Question

Hi,

I'm currently working on yolov5 algorithm and I'm wondering if it's possible to have access to all detections results before the last one of an object. To clearer for example if on one image there is a boat at the end, the output will be a boxe with the confidence rate of the boat, but before that the algorithm must have predicted something other than a boat and that's what I'd like to have as data . So I just want to know if it possible to have an idea on where I should modifiy the code. I have already tried on the general.py, and in the visualization part of yolo.py but I didn't get anything conclusive.

Thanks for your help

Additional

No response

github-actions[bot] commented 1 year ago

👋 Hello @ibou810, 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

@ibou810 hi,

To access all the detection results before the final one, you can modify the code in the detect.py file. Specifically, you would need to make changes in the section where the detections are processed and returned.

You can find this section in the detect function of detect.py file. By examining and modifying this function, you can access the intermediate detection results.

I hope this helps! Let me know if you have any further questions or need additional assistance.

ibou810 commented 1 year ago

Thank you very much for your response. Actually I tried to modify the code and see what pred because I think that it's in the part of the code bellow that I can get the intermediate detection results if I'm not mistaken . Please correct me if its wrong

with dt[1]: visualize = increment_path(save_dir / Path(path).stem, mkdir=True) if visualize else False pred = model(im, augment=augment, visualize=visualize)

But the fact is I don't understand what model really do. Thank you

glenn-jocher commented 1 year ago

@ibou810 you are welcome! Yes, you are correct that modifying the code in the section you provided can allow you to access the intermediate detection results.

In the section of the code you included, model is the function that performs the object detection. Essentially, the model function takes in the input image, im, and applies a series of operations to produce a set of predictions or detections, pred, for any objects present in the image.

If you want to understand what happens in the model function and how exactly the detections are performed, I recommend that you take a look at the implementation details section on the YOLOv5 GitHub page. There you can find an in-depth explanation of the architecture and how it works.

Let me know if you have any further questions or concerns.

ibou810 commented 1 year ago

Thank you for your answer it was very helpful. I just have another question, I want to know the real size of an object in cm for each detection in the image and I'm wondering were I should do that either in the general.py or in the detect.py. I tried to do some research but I didn't found anything with the yolov5 algorithm.

glenn-jocher commented 1 year ago

@ibou810 hi there,

I'm glad to hear that my previous answer was helpful to you. Regarding your new question, if you want to obtain the real size of an object in centimeters for each detection in the image, you would typically need additional information such as the distance between the camera and the object.

YOLOv5 algorithm does not directly provide the real size of objects in centimeters because it focuses on object detection and localization rather than providing absolute measurements. However, you can potentially estimate the size of objects if you have access to the camera's intrinsic parameters and the distance from the camera to the objects.

To achieve this, you would need to perform camera calibration and utilize techniques like triangulation and perspective projection. OpenCV and other computer vision libraries provide tools for camera calibration that can help you estimate the real-world measurements of objects.

I hope this clarifies the approach you can take to obtain the real size of objects. If you have any further questions, feel free to ask.

chelsea456 commented 1 year ago

Thank you very much for your response. Actually I tried to modify the code and see what pred because I think that it's in the part of the code bellow that I can get the intermediate detection results if I'm not mistaken . Please correct me if its wrong

with dt[1]:

        visualize = increment_path(save_dir / Path(path).stem, mkdir=True) if visualize else False

        pred = model(im, augment=augment, visualize=visualize)

But the fact is I don't understand what model really do.

Thank you

Hi you, have you found a way to solve this problem because i am also interested in it, because if it is, the time to predict it is much faster in the detect field of many images

glenn-jocher commented 1 year ago

@chelsea456 hi there,

To access the intermediate detection results in YOLOv5, you can modify the code in the detect.py file. Specifically, you would need to make changes in the section where the detections are processed and returned.

In the code you provided, the model function is responsible for performing the object detection. It takes in the input image, im, and applies a series of operations to produce a set of predictions or detections, pred, for any objects present in the image.

To access the intermediate detection results, you can modify the code in the detect function of detect.py file. By examining and modifying this function, you can access the intermediate pred variable before it is returned.

I hope this helps! Let me know if you have any further questions or concerns.

malekaburaddaha commented 1 year ago

How to print the training metrics (Hyperparameters excel sheet) for the test data, where should the code be added, or if there is any part in train.py that need to be copied and pasted in detect.py

@glenn-jocher

glenn-jocher commented 1 year ago

@malekaburaddaha to print the training metrics for the test data in YOLOv5, you can modify the code in the train.py file. There are a couple of places where you can add code to achieve this.

  1. During training: Inside the train.py file, you can find the train() function. Towards the end of this function, after the training loop, you can add code to print the desired training metrics for the test data. You can use the test.test() function to evaluate the model on the test dataset and obtain the metrics. You can then print these metrics as desired.

  2. After training: Alternatively, if you want to print the training metrics for the test data after training is complete, you can add code in the detect.py file. One possible approach is to load the trained model weights using torch.load() and then perform inference on the test images using the model function. You can use the results.print() function to print the desired metrics.

Please keep in mind that this is a general suggestion and you will need to modify the code based on your specific requirements and use case.

Let me know if you have any further questions or need more assistance.

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 ⭐