Last active
December 27, 2018 05:54
-
-
Save shangeth/d263dd85872fb465c519dfba137a9292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.nn as nn | |
class LRN(nn.Module): | |
def __init__(self, size, alpha=1e-4, beta=0.75, k=1): | |
super(LRN, self).__init__() | |
self.avg = nn.AvgPool3d(kernel_size =(size,1,1), stride=1, padding=int((size-1)/2)) | |
self.alpha = alpha | |
self.beta = beta | |
self.k = k | |
def forward(self, x): | |
deno = x.pow(2).unsqueeze(1) | |
deno = self.avg(deno).squeeze(1) | |
deno = deno.mul(self.alpha).add(self.k).pow(self.beta) | |
x = x.div(deno) | |
return x | |
x = torch.randn( 20,3, 10, 10) | |
lrn = nn.LocalResponseNorm(2) | |
lrn(x).size() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment