1 Star 0 Fork 7

史鑫鑫/Fatigue-Driven-Detection-Based-on-CNN

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
l2norm.py 898 Bytes
一键复制 编辑 原始数据 按行查看 历史
Revan-github 提交于 2019-06-07 14:11 . Add files via upload
import torch
import torch.nn as nn
from torch.autograd import Function
from torch.autograd import Variable
import torch.nn.init as init
import Config
class L2Norm(nn.Module):
def __init__(self,n_channels, scale):
super(L2Norm,self).__init__()
self.n_channels = n_channels
self.gamma = scale or None
self.eps = 1e-10
if Config.use_cuda:
self.weight = nn.Parameter(torch.Tensor(self.n_channels).cuda())
else:
self.weight = nn.Parameter(torch.Tensor(self.n_channels))
self.reset_parameters()
def reset_parameters(self):
nn.init.constant_(self.weight,self.gamma)
def forward(self, x):
norm = x.pow(2).sum(dim=1, keepdim=True).sqrt()+self.eps
#x /= norm
x = torch.div(x,norm)
out = self.weight.unsqueeze(0).unsqueeze(2).unsqueeze(3).expand_as(x) * x
return out
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/shi-xinxinzhao/Fatigue-Driven-Detection-Based-on-CNN.git
[email protected]:shi-xinxinzhao/Fatigue-Driven-Detection-Based-on-CNN.git
shi-xinxinzhao
Fatigue-Driven-Detection-Based-on-CNN
Fatigue-Driven-Detection-Based-on-CNN
master

搜索帮助