Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yolov8 segmenation parameter questions #14007

Closed
1 task done
Leo-aetech opened this issue Jun 26, 2024 · 7 comments
Closed
1 task done

yolov8 segmenation parameter questions #14007

Leo-aetech opened this issue Jun 26, 2024 · 7 comments
Labels
question Further information is requested

Comments

@Leo-aetech
Copy link

Search before asking

Question

We conducted an inference on yolov8m-seg as below. To know the number of parameters in the model, we checked the number of parameters using summary in the method part of the BasePredictor class.
The number of parameters in this way is 50,741,712. In link https://docs.ultralytics.com/models/yolov8/#performance-metrics, the number of parameters of yolov8m-seg is 27.3M. Why is this difference coming out?

@smart_inference_mode()
    def stream_inference(self, source=None, model=None, *args, **kwargs):
        """Streams real-time inference on camera feed and saves results to file."""
        if self.args.verbose:
            LOGGER.info("")

        # Setup model
        if not self.model:
            self.setup_model(model)
            
        from torchinfo  import summary
        summary(self.model, input_size=(1, 3,640,640))

Downloading https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8m-seg.pt to 'yolov8m-seg.pt'...
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 52.4M/52.4M [00:00<00:00, 115MB/s]

====================================================================================================
Layer (type:depth-idx) Output Shape Param #

AutoBackend [1, 116, 8400] --
├─SegmentationModel: 1-1 [1, 116, 8400] --
│ └─Sequential: 2-1 -- --
│ │ └─Conv: 3-1 [1, 48, 320, 320] (1,344)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Conv: 3-3 [1, 96, 160, 160] (41,568)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-5 [1, 96, 160, 160] (110,976)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-15 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-15 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-15 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-15 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-15 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Conv: 3-17 [1, 192, 80, 80] (166,080)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-19 [1, 192, 80, 80] (812,160)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-37 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Conv: 3-39 [1, 384, 40, 40] (663,936)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-41 [1, 384, 40, 40] (3,246,336)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-59 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Conv: 3-61 [1, 576, 20, 20] (1,991,232)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-63 [1, 576, 20, 20] (3,983,616)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-73 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-73 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-73 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-73 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-73 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─SPPF: 3-75 [1, 576, 20, 20] (830,304)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─SPPF: 3-77 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Upsample: 3-79 [1, 576, 40, 40] --
│ │ └─Concat: 3-80 [1, 960, 40, 40] --
│ │ └─C2f: 3-81 [1, 384, 40, 40] (1,992,192)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-91 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-91 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-91 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-91 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-91 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Upsample: 3-93 [1, 384, 80, 80] --
│ │ └─Concat: 3-94 [1, 576, 80, 80] --
│ │ └─C2f: 3-95 [1, 192, 80, 80] (516,864)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-105 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-105 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-105 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-105 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-105 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Conv: 3-107 [1, 192, 40, 40] (331,968)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Concat: 3-109 [1, 576, 40, 40] --
│ │ └─C2f: 3-110 [1, 384, 40, 40] (1,844,736)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-120 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-120 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-120 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-120 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-120 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Conv: 3-122 [1, 384, 20, 20] (1,327,488)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Concat: 3-124 [1, 960, 20, 20] --
│ │ └─C2f: 3-125 [1, 576, 20, 20] (4,204,800)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-135 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-135 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-135 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-135 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─C2f: 3-135 -- (recursive)
│ │ └─Segment: 3-136 -- (recursive)
│ │ └─Segment: 3-137 [1, 116, 8400] (5,203,104)

Total params: 50,741,712
Trainable params: 0
Non-trainable params: 50,741,712
Total mult-adds (G): 55.16

Input size (MB): 4.92
Forward/backward pass size (MB): 490.51
Params size (MB): 109.07
Estimated Total Size (MB): 604.50

image 1/1 /home/aetech/PycharmProjects/torch/JSW_test/ultralytics/seg_test/CH1_240415_vw_19_6_091520.jpg: 416x640 8 bottles, 1 cell phone, 17.7ms
Speed: 3.1ms preprocess, 17.7ms inference, 87.2ms postprocess per image at shape (1, 3, 416, 640)
Unable to init server: Could not connect: Connection refused

Additional

No response

@Leo-aetech Leo-aetech added the question Further information is requested label Jun 26, 2024
@glenn-jocher
Copy link
Member

Hello,

Thank you for your detailed question and for providing the code snippet. The discrepancy in the number of parameters you're observing is indeed intriguing. Let's delve into the possible reasons for this difference.

Understanding the Discrepancy

The number of parameters listed in the YOLOv8 Performance Metrics for the yolov8m-seg model is 27.3M, while your summary indicates 50,741,712 parameters. This difference could be due to several factors:

  1. Model Components: The segmentation model includes additional components such as the segmentation head, which might not be accounted for in the base model's parameter count.
  2. Parameter Counting Method: The method used to count parameters in your script might be including additional layers or components that are not part of the core model architecture.

Steps to Verify

  1. Reproducible Example: To better understand and reproduce the issue, could you please provide a minimal reproducible example? This will help us diagnose the problem more effectively. You can refer to our Minimum Reproducible Example Guide for more details.

  2. Latest Version: Ensure you are using the latest version of the Ultralytics YOLO package. Sometimes, discrepancies can arise from using outdated versions. You can update the package using:

    pip install --upgrade ultralytics

Code Example for Parameter Counting

Here's a concise example to count the parameters using the torchinfo library, which might help clarify the discrepancy:

from ultralytics import YOLO
from torchinfo import summary

# Load the YOLOv8m-seg model
model = YOLO("yolov8m-seg.pt")

# Print the model summary
summary(model.model, input_size=(1, 3, 640, 640))

This should give you a detailed breakdown of the model's architecture and parameter count.

Conclusion

The difference in parameter counts could be due to the inclusion of additional components in the segmentation model or differences in how parameters are counted. Providing a minimal reproducible example and ensuring you are using the latest version of the package will help us further investigate this issue.

Feel free to reach out if you have any more questions or need further assistance!

@Leo-aetech
Copy link
Author

Leo-aetech commented Jun 26, 2024

@glenn-jocher
Thank you so much for your kind reply.
As you said, I checked the model again, but it seems to be exactly the same model as the latest version. Is it okay if I ask you to check it again? Is it possible that the parameters in the document may not be updated?


# Load the YOLOv8m-seg model
model = YOLO("yolov8m-seg.pt")

# Print the model summary
summary(model.model, input_size=(1, 3, 640, 640))

output

Layer (type:depth-idx) Output Shape Param #

SegmentationModel [1, 116, 8400] --
├─Sequential: 1-1 -- --
│ └─Conv: 2-1 [1, 48, 320, 320] --
│ │ └─Conv2d: 3-1 [1, 48, 320, 320] (1,296)
│ │ └─BatchNorm2d: 3-2 [1, 48, 320, 320] (96)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Conv: 2-3 [1, 96, 160, 160] --
│ │ └─Conv2d: 3-4 [1, 96, 160, 160] (41,472)
│ │ └─BatchNorm2d: 3-5 [1, 96, 160, 160] (192)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-5 [1, 96, 160, 160] 101,952
│ │ └─Conv: 3-7 [1, 96, 160, 160] (9,408)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-15 -- (recursive)
│ │ └─ModuleList: 3-15 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-15 -- (recursive)
│ │ └─ModuleList: 3-15 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-15 -- (recursive)
│ │ └─ModuleList: 3-15 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-15 -- (recursive)
│ │ └─ModuleList: 3-15 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-15 -- (recursive)
│ │ └─Conv: 3-17 [1, 96, 160, 160] (18,624)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Conv: 2-17 [1, 192, 80, 80] --
│ │ └─Conv2d: 3-19 [1, 192, 80, 80] (165,888)
│ │ └─BatchNorm2d: 3-20 [1, 192, 80, 80] (384)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-19 [1, 192, 80, 80] 776,064
│ │ └─Conv: 3-22 [1, 192, 80, 80] (37,248)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─ModuleList: 3-38 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-37 -- (recursive)
│ │ └─Conv: 3-40 [1, 192, 80, 80] (110,976)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Conv: 2-39 [1, 384, 40, 40] --
│ │ └─Conv2d: 3-42 [1, 384, 40, 40] (663,552)
│ │ └─BatchNorm2d: 3-43 [1, 384, 40, 40] (768)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-41 [1, 384, 40, 40] 3,100,416
│ │ └─Conv: 3-45 [1, 384, 40, 40] (148,224)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─ModuleList: 3-61 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-59 -- (recursive)
│ │ └─Conv: 3-63 [1, 384, 40, 40] (443,136)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Conv: 2-61 [1, 576, 20, 20] --
│ │ └─Conv2d: 3-65 [1, 576, 20, 20] (1,990,656)
│ │ └─BatchNorm2d: 3-66 [1, 576, 20, 20] (1,152)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-63 [1, 576, 20, 20] 3,652,992
│ │ └─Conv: 3-68 [1, 576, 20, 20] (332,928)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─ModuleList: 3-76 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─ModuleList: 3-76 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─ModuleList: 3-76 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─ModuleList: 3-76 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─Conv: 3-78 [1, 576, 20, 20] (664,704)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─SPPF: 2-75 [1, 576, 20, 20] 664,704
│ │ └─Conv: 3-80 [1, 288, 20, 20] (166,464)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─SPPF: 2-77 -- (recursive)
│ │ └─MaxPool2d: 3-82 [1, 288, 20, 20] --
│ │ └─MaxPool2d: 3-83 [1, 288, 20, 20] --
│ │ └─MaxPool2d: 3-84 [1, 288, 20, 20] --
│ │ └─Conv: 3-85 [1, 576, 20, 20] (664,704)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Upsample: 2-79 [1, 576, 40, 40] --
│ └─Concat: 2-80 [1, 960, 40, 40] --
│ └─C2f: 2-81 [1, 384, 40, 40] 1,624,320
│ │ └─Conv: 3-87 [1, 384, 40, 40] (369,408)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-91 -- (recursive)
│ │ └─ModuleList: 3-95 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-91 -- (recursive)
│ │ └─ModuleList: 3-95 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-91 -- (recursive)
│ │ └─ModuleList: 3-95 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-91 -- (recursive)
│ │ └─ModuleList: 3-95 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-91 -- (recursive)
│ │ └─Conv: 3-97 [1, 384, 40, 40] (295,680)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Upsample: 2-93 [1, 384, 80, 80] --
│ └─Concat: 2-94 [1, 576, 80, 80] --
│ └─C2f: 2-95 [1, 192, 80, 80] 406,656
│ │ └─Conv: 3-99 [1, 192, 80, 80] (110,976)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-105 -- (recursive)
│ │ └─ModuleList: 3-107 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-105 -- (recursive)
│ │ └─ModuleList: 3-107 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-105 -- (recursive)
│ │ └─ModuleList: 3-107 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-105 -- (recursive)
│ │ └─ModuleList: 3-107 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-105 -- (recursive)
│ │ └─Conv: 3-109 [1, 192, 80, 80] (74,112)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Conv: 2-107 [1, 192, 40, 40] --
│ │ └─Conv2d: 3-111 [1, 192, 40, 40] (331,776)
│ │ └─BatchNorm2d: 3-112 [1, 192, 40, 40] (384)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Concat: 2-109 [1, 576, 40, 40] --
│ └─C2f: 2-110 [1, 384, 40, 40] 1,624,320
│ │ └─Conv: 3-114 [1, 384, 40, 40] (221,952)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-120 -- (recursive)
│ │ └─ModuleList: 3-122 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-120 -- (recursive)
│ │ └─ModuleList: 3-122 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-120 -- (recursive)
│ │ └─ModuleList: 3-122 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-120 -- (recursive)
│ │ └─ModuleList: 3-122 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-120 -- (recursive)
│ │ └─Conv: 3-124 [1, 384, 40, 40] (295,680)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Conv: 2-122 [1, 384, 20, 20] --
│ │ └─Conv2d: 3-126 [1, 384, 20, 20] (1,327,104)
│ │ └─BatchNorm2d: 3-127 [1, 384, 20, 20] (768)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Concat: 2-124 [1, 960, 20, 20] --
│ └─C2f: 2-125 [1, 576, 20, 20] 3,652,992
│ │ └─Conv: 3-129 [1, 576, 20, 20] (554,112)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-135 -- (recursive)
│ │ └─ModuleList: 3-137 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-135 -- (recursive)
│ │ └─ModuleList: 3-137 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-135 -- (recursive)
│ │ └─ModuleList: 3-137 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-135 -- (recursive)
│ │ └─ModuleList: 3-137 -- (recursive)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─C2f: 2-135 -- (recursive)
│ │ └─Conv: 3-139 [1, 576, 20, 20] (664,704)
│ └─Segment: 2-136 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ └─Segment: 2-137 [1, 116, 8400] --
│ │ └─Proto: 3-141 [1, 32, 160, 160] (818,176)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─Proto: 3-145 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─Proto: 3-145 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-171 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─ModuleList: 3-175 -- (recursive)
│ │ └─ModuleList: 3-176 -- (recursive)
│ │ └─DFL: 3-177 [1, 4, 8400] (16)

Total params: 50,773,504
Trainable params: 0
Non-trainable params: 50,773,504
Total mult-adds (G): 55.11

Input size (MB): 4.92
Forward/backward pass size (MB): 929.60
Params size (MB): 109.14
Estimated Total Size (MB): 1043.66

cfg

Ultralytics YOLO 🚀, AGPL-3.0 license

YOLOv8-seg instance segmentation model. For Usage examples see https://docs.ultralytics.com/tasks/segment

Parameters

nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n-seg.yaml' will call yolov8-seg.yaml with scale 'n'

[depth, width, max_channels]

n: [0.33, 0.25, 1024]
s: [0.33, 0.50, 1024]
m: [0.67, 0.75, 768]
l: [1.00, 1.00, 512]
x: [1.00, 1.25, 512]

YOLOv8.0n backbone

backbone:

[from, repeats, module, args]

  • [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
  • [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
  • [-1, 3, C2f, [128, True]]
  • [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
  • [-1, 6, C2f, [256, True]]
  • [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
  • [-1, 6, C2f, [512, True]]
  • [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
  • [-1, 3, C2f, [1024, True]]
  • [-1, 1, SPPF, [1024, 5]] # 9

YOLOv8.0n head

head:

  • [-1, 1, nn.Upsample, [None, 2, "nearest"]]

  • [[-1, 6], 1, Concat, [1]] # cat backbone P4

  • [-1, 3, C2f, [512]] # 12

  • [-1, 1, nn.Upsample, [None, 2, "nearest"]]

  • [[-1, 4], 1, Concat, [1]] # cat backbone P3

  • [-1, 3, C2f, [256]] # 15 (P3/8-small)

  • [-1, 1, Conv, [256, 3, 2]]

  • [[-1, 12], 1, Concat, [1]] # cat head P4

  • [-1, 3, C2f, [512]] # 18 (P4/16-medium)

  • [-1, 1, Conv, [512, 3, 2]]

  • [[-1, 9], 1, Concat, [1]] # cat head P5

  • [-1, 3, C2f, [1024]] # 21 (P5/32-large)

  • [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Segment(P3, P4, P5)

@glenn-jocher
Copy link
Member

@Leo-aetech hello,

Thank you for your detailed follow-up and for providing the code snippet and output. I appreciate your diligence in verifying the model parameters.

The discrepancy you're observing between the documented parameters (27.3M) and the parameters reported by your script (50,773,504) is indeed puzzling. Here are a few points to consider:

Potential Reasons for Discrepancy

  1. Model Components: The segmentation model includes additional components such as the segmentation head, which might not be accounted for in the base model's parameter count.
  2. Parameter Counting Method: The method used to count parameters in your script might be including additional layers or components that are not part of the core model architecture.

Steps to Verify

  1. Reproducible Example: To better understand and reproduce the issue, could you please provide a minimal reproducible example? This will help us diagnose the problem more effectively. You can refer to our Minimum Reproducible Example Guide for more details.

  2. Latest Version: Ensure you are using the latest version of the Ultralytics YOLO package. Sometimes, discrepancies can arise from using outdated versions. You can update the package using:

    pip install --upgrade ultralytics

Code Example for Parameter Counting

Here's a concise example to count the parameters using the torchinfo library, which might help clarify the discrepancy:

from ultralytics import YOLO
from torchinfo import summary

# Load the YOLOv8m-seg model
model = YOLO("yolov8m-seg.pt")

# Print the model summary
summary(model.model, input_size=(1, 3, 640, 640))

This should give you a detailed breakdown of the model's architecture and parameter count.

Conclusion

The difference in parameter counts could be due to the inclusion of additional components in the segmentation model or differences in how parameters are counted. Providing a minimal reproducible example and ensuring you are using the latest version of the package will help us further investigate this issue.

Feel free to reach out if you have any more questions or need further assistance!

@AISTALK
Copy link

AISTALK commented Aug 5, 2024

glenn-jocher answer like GPT :(

I also confused about total parameters in models.

@pderrenger
Copy link
Member

Thank you for your comment. The discrepancy in the total parameters you're seeing might be due to differences in how parameters are counted or additional components in the segmentation model. Please ensure you're using the latest version of the Ultralytics YOLO package and verify the parameter count again. If the issue persists, providing a minimal reproducible example would help us investigate further. Feel free to reach out with any more questions.

@6DammK9
Copy link

6DammK9 commented Sep 25, 2024

@AISTALK @Leo-aetech
Currently I'm hunting the issue that torchinfo may count the parameters incorrectly. Overestimated up to 2.37x for my case.

This approach will yield 27.3M matching the docuements.

from ultralytics import YOLO

# Load the YOLOv8m-seg model
model = YOLO("yolov8m-seg.pt")

# It is a pytorch model, so we can count it directrly.
pytorch_total_params = sum(p.numel() for p in model.parameters())

# 27285968
print(pytorch_total_params)

@AISTALK
Copy link

AISTALK commented Sep 25, 2024

@AISTALK @Leo-aetech Currently I'm hunting the issue that torchinfo may count the parameters incorrectly. Overestimated up to 2.37x for my case.

This approach will yield 27.3M matching the docuements.

from ultralytics import YOLO

# Load the YOLOv8m-seg model
model = YOLO("yolov8m-seg.pt")

# It is a pytorch model, so we can count it directrly.
pytorch_total_params = sum(p.numel() for p in model.parameters())

# 27285968
print(pytorch_total_params)

@6DammK9 That's because docs do not count model's head params as params. In docs there are only sizes of model's backbones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants