Feature Mapping and Filter Viz. in YOLO

Ashutosh Kumar
3 min readDec 24, 2021

--

YOLO(You Only Look Once) is one of the proficient methods for object detection and is customizable in a number of ways. For any research, it’s important to understand the concept behind any architecture if you want to build something otherwise we can simply implement the algorithm to get the result we need.

YOLO architecture

This is the standard YOLO architecture with 24 convolutional layers followed by 2 fully connected layers. The input image size is 448 x 448 and the filter size is 7 x 7. However there any many versions, YOLOv5 being the latest one and the numbers may vary(for e.g. YOLOv3 has a total of 53 layers). The architecture contains Darknet53 and a few versions have the GooLeNet model for image classification.

The major application of feature mapping and filter visualization comes in handy while doing transfer learning to train your custom dataset in the pre-trained YOLO model. In transfer learning, we need to randomize certain layers and for that, we need to know the layers that are detecting the object from the image naively. So, without further ado, let’s know how we can do that in YOLO.

The first step is to import all the modules that we’re gonna use to build YOLO from scratch. Check below -

Moving straight on to build out YOLO architecture with 24 convolutional layers only, given as —

We have now built our YOLO model and the further task is to analyze all the convolution layers and filters. I’m gonna start with the first convolution layer and plot all the filters in that particular layer.

Filters of the first convolutional layer

In the above image, it’s evident that there are 64 filters( the same number of filters our first convolution layer has), thus using the figuresize of 8 x 8. The next step is to analyze these filters on a test image. But before that let’s have a truncated model to test out layers explicitly. The code to do that is -

Input image(448 x 448)

Finally, let’s implement the feature mapping and visualize the filters for the above input image.

Results

I have used 10 convolution layers to analyze my filters and prepare the feature map, you can use as many layers as you want to by simply changing the layer array.

You can find the complete Github code here.

This blog is the result of my inability to find out the method for feature mapping and filter visualization in YOLO architecture on the internet. In the end, I had to build it from scratch and thus I’m sharing this to help others find it here.

~Ashutosh

--

--