Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adaptive Kernel Size not implemented

See original GitHub issue

It seems that the implementation under models/ differs from the paper’s adaptive setting for k_size, given in Fig 3 of the paper.

Why do the resnet, mobilenet modules not use adaptive kernel sizes?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

ykk648commented, Jul 3, 2020
class EcaLayer(nn.Module):

    def __init__(self, channels, gamma=2, b=1):
        super(EcaLayer, self).__init__()
        self.avg_pool = nn.AdaptiveAvgPool2d(1)

        t = int(abs((math.log(channels, 2) + b) / gamma))
        k_size = t if t % 2 else t + 1
        self.conv = nn.Conv1d(1, 1, kernel_size=k_size, padding=(k_size - 1) // 2, bias=False)

        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        # feature descriptor on the global spatial information
        y = self.avg_pool(x)

        # Two different branches of ECA module
        y = self.conv(y.squeeze(-1).transpose(-1, -2)).transpose(-1, -2).unsqueeze(-1)

        # Multi-scale information fusion
        y = self.sigmoid(y)

        return x * y.expand_as(x)
15114218commented, Dec 17, 2020

I meet an error, who can help me? thanks a lot. RuntimeError: The expanded size of the tensor (64) must match the existing size (63) at non-singleton dimension 1. Target sizes: [8, 64, 256, 256]. Tensor sizes: [8, 63, 1, 1]

class eca_layer(nn.Module): “”"Constructs a ECA module.

    channel: Number of channels of the input feature map
    k_size: Adaptive selection of kernel size

def __init__(self, k_size, gamma=2, b=1):
    super(eca_layer, self).__init__()
    self.k_size = k_size
    self.gamma = gamma
    self.b = b
    self.avg_pool = nn.AdaptiveAvgPool2d(1)
    self.conv = nn.Conv1d(1, 1, kernel_size=self.k_size, padding=(self.k_size - 1) // 2, bias=False)
    self.sigmoid = nn.Sigmoid()

def forward(self, x):
    b, c, h, w = x.size()
    t = int(abs((math.log(c, 2) + self.b) / self.gamma))
    self.k_size = t if t % 2 else t + 1        
    y = self.avg_pool(x)
    y = self.conv(y.squeeze(-1).transpose(-1, -2)).transpose(-1, -2).unsqueeze(-1)      
    y = self.sigmoid(y)
    return x * y.expand_as(x)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Adaptive Convolutional Kernels - CVF Open Access
We used the ResNet18[6] topology to implement adap- tive kernels in it. In this experiment, only the first layer was changed to use...
Read more >
How does adaptive pooling in pytorch work? - Stack Overflow
In general, pooling reduces dimensions. If you want to increase dimensions, you might want to look at interpolation.
Read more >
Adaptive Kernel Density Estimation - SAGE Journals
Kernel density estimates are asymtotically biased, with a bias varying with the bandwidth and the shape of the underlying 'true' density function. For...
Read more >
Variable kernel density estimation - Wikipedia
In statistics, adaptive or "variable-bandwidth" kernel density estimation is a form of kernel density estimation in which the size of the kernels used...
Read more >
Adaptive kernel selection network with attention constraint for ...
Specifically, the two convolution layers are conducted by a 3 \times 3 kernel size and a 5 \times 5 kernel size, respectively.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found