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

I think it's a general problem when the input to the functional layer is dynamic. #248

Open
khadijabef opened this issue Jul 2, 2021 · 0 comments

Comments

@khadijabef
Copy link

I think it's a general problem when the input to the functional layer is dynamic.
I had a situation where functional avg_pool3d that depended on the shape of the previous layer's outputs. One has to either make the kernel constant or switch to non-functional pytorch's api.

Does anybody know how can I make the kernel size static here ?

class GeM(nn.Module):
def init(self, p=3, eps=1e-6):
super(GeM,self).init()
self.p = nn.Parameter(torch.ones(1)*p)
self.eps = eps

def forward(self, x):
    return self.gem(x, p=self.p, eps=self.eps)

def gem(self, x, p=3, eps=1e-6):
    return F.avg_pool2d(x.clamp(min=eps).pow(p), (x.size(-2), x.size(-1))).pow(1./p)

def __repr__(self):
    return self.__class__.__name__ + '(' + 'p=' + '{:.4f}'.format(self.p.data.tolist()[0]) + ', ' + 'eps=' + str(self.eps) + ')'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant