Skip to content

Passing a single layer (e.g., nn.Conv2d) resulted in 0 params #115

@Yui-Arthur

Description

@Yui-Arthur

Search before reporting

  • I have searched the appropriate Ultralytics issues and found no similar bug report.

Repository or project

https://github.com/ultralytics/thop

Component / area

No response

Bug description

  • Got the zero parameters when profile a single layer (e.g. nn.Conv2d)

Environment

  • OS: Windows11 24H2
  • Python: 3.12.12
  • Install: git

Package Version

  • filelock: 3.20.0
  • fsspec: 2025.12.0
  • Jinja2: 3.1.6
  • MarkupSafe: 2.1.5
  • mpmath: 1.3.0
  • networkx: 3.6.1
  • numpy: 2.3.5
  • packaging: 25.0
  • pillow: 12.0.0
  • pip: 26.0.1
  • setuptools: 80.10.2
  • sympy: 1.14.0
  • torch: 2.10.0+cu128
  • torchvision: 0.25.0+cu128
  • typing_extensions: 4.15.0
  • wheel: 0.46.3

Minimal reproducible example

from thop import profile
import torch
import torch.nn as nn

class test_model(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer = nn.Conv2d(3, 10, (3,3))

    def forward(self, input):
        return self.layer(input)


layer = nn.Conv2d(3, 10, (3,3))
model = test_model()

macs, weight = profile(layer, torch.zeros(1,3,224,224))
print("Single Layer Profile Weights: ", weight)
# Single Layer Profile Weights:  0
macs, weight = profile(model, torch.zeros(1,3,224,224))
print("Model Profile Weights: ", weight)
# Model Profile Weights:  280.0

Additional context

  • In example, the weights of nn.Conv2d(3, 10, (3,3)) should be 280 but got 0

Are you willing to submit a PR?

  • Yes, I'd like to help by submitting a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions