<p>Set <code>export = True</code> at the yolo head. If the <code>net</code> is the <code>AutoShape</code> instance, you can achieve it by:</p>
<pre><code>m = net.model.model.model[-1] if net.dmb else net.model.model[-1]
m.export = False  # Allow obtaining features after detection/segmentation head
</code></pre>
<p>Also, you might need to fix non maxima suppression to pass the correct features.</p>

CC BY-SA 4.0
2023-10-23T11:12:19.373Z
2023-10-23T11:12:19.373Z
8ToThePowerOfMol
<p>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).</p>
<p>Today, I spent a lot of time to understand how I can extract the high-level features from YOLOv5.</p>
<p>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 <a href="https://github.com/ultralytics/yolov5/blob/868c0e9bbb45b031e7bfd73c6d3983bcce07b9c1/models/yolo.py" rel="nofollow noreferrer">here</a>.</p>
<p>Second question, from which layer should I extract the features of final predicted objects?</p>
<p>Thank you so much for any help! I am really stuck for a long time. :(</p>

CC BY-SA 4.0
2023-04-04T19:46:17.103Z
I recommend you read this StackExchange [post](https://stackoverflow.com/questions/73440468/where-to-find-the-yolov5-feature-extractor).
Brian O'Donnell
CC BY-SA 4.0
2023-04-05T17:04:27.440Z
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
Community
<object-detection><yolo><feature-extraction>
How to extract the high-level features of YOLOv5?
Hamzah Al-Qadasi
# How to extract the high-level features of YOLOv5?

(Asked by: username_0 on 2023-04-04)

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](https://github.com/ultralytics/yolov5/blob/868c0e9bbb45b031e7bfd73c6d3983bcce07b9c1/models/yolo.py).

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. :(

**Tags:** object-detection, yolo, feature-extraction

> **Comments:**
> **username_1**: I recommend you read this StackExchange [post](https://stackoverflow.com/questions/73440468/where-to-find-the-yolov5-feature-extractor).  
> **username_2**: Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.  

---

## 1 answers

### Answer by username_3 on 2023-10-23. Score: 1 | Accepted answer

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.


---

