1 Star 0 Fork 1

ink/Pytorch_AlexNet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lrn_module.py 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
ink 提交于 2020-08-10 08:07 . mophy 001 update
import torch.nn as nn
from torch.nn import functional as F
from torch.autograd import Variable
class LRN(nn.Module):
def __init__(self, alpha=1.0, beta=0.75, ACROSS_CHANNELS=False, local_size=1):
super(LRN, self).__init__()
self.local_size = local_size
self.ACROSS_CHANNELS = ACROSS_CHANNELS
if self.ACROSS_CHANNELS:
self.average = nn.AvgPool3d(kernel_size=(local_size, 1,1),
stride=1,
padding=(int((local_size-1.0)/2),0,0))
else:
self.average = nn.AvgPool2d(kernel_size=local_size, stride=1, padding=int((local_size-1.0)/2))
self.alpha = alpha
self.beta = beta
def forward(self, x):
if self.ACROSS_CHANNELS:
div = x.pow(2).unsqueeze(1)
div = self.average(div).squeeze(1)
div = div.mul(self.alpha).add(1.0).pow(self.beta)
else:
div = x.pow(2)
div = self.average(div)
div = div.mul(self.alpha).add(1.0).pow(self.beta)
x = x.div(div)
return x
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/inkCode/Pytorch_AlexNet.git
git@gitee.com:inkCode/Pytorch_AlexNet.git
inkCode
Pytorch_AlexNet
Pytorch_AlexNet
master

搜索帮助