How to extract information from method _inference within the Detect class? #14340
-
Hello! First, I want to express my sincere gratitude to the entire development team for the fantastic YOLOv8 project and for your contributions to the open-source community! My research group is currently working on a computer vision project that involves approximating the YOLO model for various images. The project's goal is to optimize the performance of a computer vision application for small devices using our approximator and, simultaneously, develop a module to interpret the detected objects in the images by approximating the penultimate layer of the YOLO model. To achieve this, we need to extract the weights from the penultimate layer of the model for each image during inference. We have been using the register_forward_hook() function from the PyTorch framework and managed to access the weights of the following layers: What we truly need are the weights from the layers encoded by the following variables: The screenshot above is from We have attempted to put our project in "developer mode" for our experiments, following the guidance provided here: https://docs.ultralytics.com/quickstart/#how-do-i-clone-the-ultralytics-repository-for-development However, we have not succeeded in making changes to the structure of the ultralytics package that yield the desired results. Could you please advise us on how to extract intermediate data from the _inference method of the Detect class? Thank you very much for your assistance. Best regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello! Thank you for your kind words and for your interest in the YOLOv8 project! We're thrilled to hear about your research and its innovative applications. To extract intermediate data from the Here's a step-by-step approach to achieve this:
If you encounter any issues or need further assistance, please ensure you are using the latest version of the Ultralytics package. You can update it using: pip install --upgrade ultralytics For more detailed guidance on creating a minimum reproducible example, please refer to our documentation. I hope this helps! If you have any further questions, feel free to ask. Good luck with your research! 🚀 |
Beta Was this translation helpful? Give feedback.
Hello!
Thank you for your kind words and for your interest in the YOLOv8 project! We're thrilled to hear about your research and its innovative applications.
To extract intermediate data from the
_inference
method within theDetect
class, you can indeed leverage PyTorch'sregister_forward_hook()
function. However, since you need data from specific intermediate layers, you might need to modify the model slightly to make these layers accessible.Here's a step-by-step approach to achieve this:
Clone the Repository for Development: Ensure you have cloned the repository and set it up for development as per the quickstart guide.
Modify the Model: You can modify the
Detect
class to include h…