What is the real number of CNN layers in yolov3?
Asked Answered
F

3

5

I'm really confused with the architecture of yolov3. I've read the documentation and paper about it. Some people say that it has 103 convolutional layers, some others say that it has 53 layers. But when you count the convolutional layers in the .cfg file (after downloading it) it comes to about 75! ...What is missed here? What should I do to find it? This question is important for us because we need to cite this architecture in a paper and we need to know the exact size of the layers...

Fanlight answered 1/3, 2019 at 16:32 Comment(0)
D
7

According to AlexeyAB (creator of very popular forked Darknet version and creator of YOLO v4) https://groups.google.com/forum/?nomobile=true#!topic/darknet/9WppEzRouMU

Yolo has
75 cnn-layers (convolutional layers) + 31 other layers (shortcut, route, upsample, yolo) = 106 layers in total.

Remember that Yolo V3 does detection at 3 different scales, which are at layer 82,94,106 https://gist.github.com/fabito/a49bb6a5593594f26275bc90baba6e32

Discipline answered 6/3, 2019 at 9:1 Comment(0)
P
1

It looks like in this case there can be a variable number of layers in this model. In the paper it says that Darknet53 has 53 layers. But in their train.py file they have a cutoff for the number of layers based on the Darknet model that you are using. Specifically:

def load_darknet_weights(self, weights, cutoff=-1):
    # Parses and loads the weights stored in 'weights'
    # cutoff: save layers between 0 and cutoff (if cutoff = -1 all are saved)
    weights_file = weights.split(os.sep)[-1]

    # Try to download weights if not available locally
    if not os.path.isfile(weights):
        try:
            os.system('wget https://pjreddie.com/media/files/' + weights_file + ' -O ' + weights)
        except IOError:
            print(weights + ' not found')

    # Establish cutoffs
    if weights_file == 'darknet53.conv.74':
        cutoff = 75
    elif weights_file == 'yolov3-tiny.conv.15':
        cutoff = 15

This piece of code is saying that if you are using the Darknet convulsion 74 file there will the cutoff for the number of layers will be 75. And it you are using the Darknet convulsion 15 file there will be a cutoff at 15 layers.

So you need to inspect which Darknet file you downloaded and determine which version you used. Based on that, I would go with the 75 since it seems that you used the darknet54.conv.74

Moreover if you view their weights Repo you can see that there is a cutoff for 75 layers if you simply do a pull from their Github and do no customizations, so it seems there is 75 layers in their file.

It is worth noting that their paper came out in April 2018, so in that time they could have added more layers to their CNN on their Github.

Potassium answered 1/3, 2019 at 16:59 Comment(3)
thanks a lot.This was really helpful.I counted all convolutional layers in the file that i downloaded and it was about 75 layers.based on what you mensioned , i think 75 is the right answerFanlight
From what I understand, Yolo does detection at 3 different scales, which are at layer 82,94,106. Thats why when you train your model it always shows those layers. So how come it is cut to only 75 layer?Discipline
look here : gist.github.com/fabito/a49bb6a5593594f26275bc90baba6e32 total layers is 106Discipline
C
0

YOLO v3 has 107 layers in total, you should also count shortcut layers, route layers, upsample layers, and YOLO layers(32 in total). So, there are 75+32=107 layers in total. When you see indexes in shortcut or route layers, you will find that we count from 0. Therefore, yolo layers are in 82,94,106 layers.

Calculated answered 3/4, 2022 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.