GithubHelp home page GithubHelp logo

Comments (3)

glenn-jocher avatar glenn-jocher commented on June 2, 2024

Hello! 👋 It sounds like you're deep into exploring YOLOv5's output formats; I'll do my best to clarify.

The output discrepancy you see mainly stems from different configurations for exporting the model. The output from export.py (1, 25200, 133) primarily deals with post-processed detections which combine all grid cells and anchor boxes across all scales into a single dimension. This format is useful for direct deployment uses where a consolidated list of predictions is more practical.

Contrastingly, when you modify the forward function, you get the outputs arranged by each detection layer (i.e., (1, 399, 80, 80), (1, 256, 40, 40), and (1, 512, 20, 20)). Each tuple reflects:

  • The number of batches
  • The number of anchors multiplied by the number of detection classes plus box attributes (5 for x, y, width, height, confidence level)
  • The grid size

Each detection layer's output corresponds to different scales at which the model detects objects. The smaller grid sizes detect larger objects, and the larger grid sizes detect smaller objects due to the receptive field of the convolutional layers.

If you're converting to another platform like RKNN and encountering shape issues, it's essential to ensure that the output dimensions expected by your RKNN implementation match the output shapes provided by the YOLOv5 model. You may need to adjust either the export script or your RKNN input processing accordingly to match these dimensions.

I hope this clarification helps! If there are more questions or a need for further help, feel free to ask. Happy coding! 😊

from yolov5.

lllittleX avatar lllittleX commented on June 2, 2024

Thank you very much for your reply. Your answer has helped me resolve part of my confusion, but there is still something I don't understand. After encountering this issue with the output shape, I also printed the shape in detect.py. Why is the shape of its prediction torch.Size([1, 15120, 133]), torch.Size([1, 3, 48, 80, 133]), torch.Size([1, 3, 24, 40, 133]), torch.Size([1, 3, 12, 20, 133])? Was there any additional processing done to these outputs? Why is the output (48, 80) instead of (80, 80)?

from yolov5.

glenn-jocher avatar glenn-jocher commented on June 2, 2024

@lllittleX hello again! Glad to hear the previous response was somewhat helpful!

The shapes you're seeing in detect.py are due to the processing and design of YOLOv5's architecture, which uses different sizes of feature maps to detect objects at various scales.

  • torch.Size([1, 15120, 133]) represents the flattened form of predictions combining all scales.
  • torch.Size([1, 3, 48, 80, 133]), torch.Size([1, 3, 24, 40, 133]), and torch.Size([1, 3, 12, 20, 133]) are predictions from three different scales. The dimensions 48x80, 24x40, and 12x20 reflect different grid sizes each layer uses to capture features of various extents.

The reason grids are not square (e.g., 80x80), but rather rectangular (48x80), is based on the input image aspect ratio and how it's processed and downsampled through the network layers, maintaining a certain aspect ratio. This means that the neural network architecture is designed in such a way to best capture the features relevant for detection tasks, given the original input dimensions and desired efficiency.

Keep diving into the details; that's how you get the best out of these models! 😉 Happy coding!

from yolov5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.