1

I am testing this code, to compare model parameters, which will help me to modify the models/layers, but I don't know which method gives me the actual number of parameters.

from torchsummary import summary
import torchinfo
from ultralytics.nn.tasks import DetectionModel
yolo_model = DetectionModel(cfg, nc=80 )
summary(yolo_model,(3, 640, 640))
torchinfo.summary( yolo_model, (3, 640, 640), batch_dim = 0)

Result from torchinfo:

=======================================
Total params: 5,257,936
Trainable params: 5,257,920
Non-trainable params: 16
Total mult-adds (G): 4.37
====================================================================================================
Input size (MB): 4.92
Forward/backward pass size (MB): 232.15
Params size (MB): 12.63
Estimated Total Size (MB): 249.70
====================================================================================================

Result from torchsummary:

==========================================================================================
Total params: 1,312,416
Trainable params: 1,312,400
Non-trainable params: 16
Total mult-adds (G): 1.39
==========================================================================================
Input size (MB): 4.69
Forward/backward pass size (MB): 128.38
Params size (MB): 5.01
Estimated Total Size (MB): 138.08
==========================================================================================

Beside this, the number of parameters printed by yolov8 itself is different. Please let me know best way to get the actual number of parameters.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
rakeshKM
  • 53
  • 6

1 Answers1

0

Variations in parameter counts across analysis methods can arise due to the complexity of the model itself. I've encountered similar situations in my own projects.

You've used three distinct methods to assess parameter counts, giving varying results: torchsummary, torchinfo, and yolov8’s own report. The first two methods are good choices for obtaining architectural insights and even parameter counts. However, the differences you're observing might come from how they handle custom layers in yolov8.

Furthermore, yolov8 model's internal parameter count can be influenced by factors such as initialization methods which may contribute to the observed differences compared to external analysis methods.

From prior experience, I’d suggest you to thoroughly explore the architecture, specifically focusing on custom or external layers that could be impacting the parameter calculations. Then align the layers present in the model with those that torchsummary and torchinfo are optimized to handle. I have even found diving into the source code of the model helpful to comprehend how it calculates and presents parameter counts.

Natália
  • 34
  • 1