I am faimilar with extracting the high-level features from any pretrained model for classification problem such as ResNet version, VGG, etc. It is easy to extract the features because there is a fully connected layer after the convolutional layers and the high-level features are usually extracted from the penultimate layer (the output of neurons of the layer before softmax layer).

Today, I spent a lot of time to understand how I can extract the high-level features from YOLOv5.

Firstly, I want to ask please, how do the high-level features look like? I mean what is the shape of the features, because I do not see any fully connected layer in the repository here.

Second question, from which layer should I extract the features of final predicted objects?

Thank you so much for any help! I am really stuck for a long time. :(

  • $\begingroup$ I recommend you read this StackExchange post. $\endgroup$ Commented Apr 4, 2023 at 19:46
  • $\begingroup$ Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. $\endgroup$
    – Community Bot
    Commented Apr 5, 2023 at 17:04

1 Answer 1


Set export = True at the yolo head. If the net is the AutoShape instance, you can achieve it by:

m = net.model.model.model[-1] if net.dmb else net.model.model[-1]
m.export = False  # Allow obtaining features after detection/segmentation head

Also, you might need to fix non maxima suppression to pass the correct features.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .