python get score gain_Python functional.linear方法代码示例
本文整理汇总了Python中torch.nn.functional.linear方法的典型用法代码示例。如果您正苦于以下问题:Python functional.linear方法的具体用法?Python functional.linear怎么用?Python functional.linear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块torch.nn.functional的用法示例。
在下文中一共展示了functional.linear方法的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: forward
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x):
"""
forward pass of the layer
:param x: input
:return: y => output
"""
from torch.nn.functional import linear
return linear(x, self.weight * self.scale,
self.bias if self.use_bias else None)
# -----------------------------------------------------------------------------------
# Pixelwise feature vector normalization.
# reference:
# https://github.com/tkarras/progressive_growing_of_gans/blob/master/networks.py#L120
# -----------------------------------------------------------------------------------
开发者ID:akanimax,项目名称:BMSG-GAN,代码行数:18,
示例2: inverse_no_cache
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def inverse_no_cache(self, inputs):
"""Cost:
output = O(D^3 + D^2N)
logabsdet = O(D^3)
where:
D = num of features
N = num of inputs
"""
batch_size = inputs.shape[0]
outputs = inputs - self.bias
outputs, lu = torch.gesv(outputs.t(), self._weight) # Linear-system solver.
outputs = outputs.t()
# The linear-system solver returns the LU decomposition of the weights, which we
# can use to obtain the log absolute determinant directly.
logabsdet = -torch.sum(torch.log(torch.abs(torch.diag(lu))))
logabsdet = logabsdet * torch.ones(batch_size)
return outputs, logabsdet
开发者ID:bayesiains,项目名称:nsf,代码行数:19,
示例3: forward
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, input, hx, att_score):
"""
References
----------
https://github.com/pytorch/pytorch/blob/v0.4.1/torch/nn/_functions/rnn.py#L49
"""
gi = F.linear(input, self.weight_ih, self.bias_ih)
gh = F.linear(hx, self.weight_hh, self.bias_hh)
i_r, i_z, i_n = gi.chunk(3, 1)
h_r, h_z, h_n = gh.chunk(3, 1)
resetgate = torch.sigmoid(i_r + h_r)
# updategate = torch.sigmoid(i_z + h_z)
newgate = torch.tanh(i_n + resetgate * h_n)
# hy = newgate + updategate * (hx - newgate)
att_score = att_score.view(-1, 1)
hy = (1. - att_score) * hx + att_score * newgate
return hy
开发者ID:GitHub-HongweiZhang,项目名称:prediction-flow,代码行数:25,
示例4: forward
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, inputs, labels):
cos_th = F.linear(inputs, F.normalize(self.weight))
cos_th = cos_th.clamp(-1, 1)
sin_th = torch.sqrt(1.0 - torch.pow(cos_th, 2))
cos_th_m = cos_th * self.cos_m - sin_th * self.sin_m
cos_th_m = torch.where(cos_th > self.th, cos_th_m, cos_th - self.mm)
cond_v = cos_th - self.th
cond = cond_v <= 0
cos_th_m[cond] = (cos_th - self.mm)[cond]
if labels.dim() == 1:
labels = labels.unsqueeze(-1)
onehot = torch.zeros(cos_th.size()).cuda()
onehot.scatter_(1, labels, 1)
outputs = onehot * cos_th_m + (1.0 - onehot) * cos_th
outputs = outputs * self.s
return outputs
开发者ID:pudae,项目名称:kaggle-humpback,代码行数:20,
示例5: get_loadings
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def get_loadings(self) -> np.ndarray:
"""Extract per-gene weights (for each Z, shape is genes by dim(Z)) in the linear decoder."""
# This is BW, where B is diag(b) batch norm, W is weight matrix
if self.use_batch_norm is True:
w = self.decoder.factor_regressor.fc_layers[0][0].weight
bn = self.decoder.factor_regressor.fc_layers[0][1]
sigma = torch.sqrt(bn.running_var + bn.eps)
gamma = bn.weight
b = gamma / sigma
bI = torch.diag(b)
loadings = torch.matmul(bI, w)
else:
loadings = self.decoder.factor_regressor.fc_layers[0][0].weight
loadings = loadings.detach().cpu().numpy()
if self.n_batch > 1:
loadings = loadings[:, : -self.n_batch]
return loadings
开发者ID:YosefLab,项目名称:scVI,代码行数:20,
示例6: LSTMCell
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def LSTMCell(input, hidden, w_ih, w_hh, b_ih=None, b_hh=None):
"""
A modified LSTM cell with hard sigmoid activation on the input, forget and output gates.
"""
hx, cx = hidden
gates = F.linear(input, w_ih, b_ih) + F.linear(hx, w_hh, b_hh)
ingate, forgetgate, cellgate, outgate = gates.chunk(4, 1)
ingate = hard_sigmoid(ingate)
forgetgate = hard_sigmoid(forgetgate)
cellgate = F.tanh(cellgate)
outgate = hard_sigmoid(outgate)
cy = (forgetgate * cx) + (ingate * cellgate)
hy = outgate * F.tanh(cy)
return hy, cy
开发者ID:chenyangh,项目名称:SemEval2019Task3,代码行数:20,
示例7: forward
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x):
# Pass Add bias.
x += self.bias
# Evaluate activation function.
if self.act == "linear":
pass
elif self.act == 'lrelu':
x = F.leaky_relu(x, self.alpha, inplace=True)
x = x * np.sqrt(2) # original repo def_gain=np.sqrt(2).
# Scale by gain.
if self.gain != 1:
x = x * self.gain
return x
开发者ID:tomguluson92,项目名称:StyleGAN2_PyTorch,代码行数:18,
示例8: forward
点赞 6
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x):
if self.zero_mean:
lrt_mean = 0.0
else:
lrt_mean = F.linear(x, self.W)
if self.bias is not None:
lrt_mean = lrt_mean + self.bias
sigma2 = Variable.exp(self.log_alpha) * self.W * self.W
if self.permute_sigma:
sigma2 = sigma2.view(-1)[torch.randperm(self.in_features * self.out_features).cuda()].view(self.out_features, self.in_features)
lrt_std = Variable.sqrt(1e-16 + F.linear(x * x, sigma2))
if self.training:
eps = Variable(lrt_std.data.new(lrt_std.size()).normal_())
else:
eps = 0.0
return lrt_mean + lrt_std * eps
开发者ID:da-molchanov,项目名称:variance-networks,代码行数:20,
示例9: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x):
"""Forward feature from the regression head to get integral result of
bounding box location.
Args:
x (Tensor): Features of the regression head, shape (N, 4*(n+1)),
n is self.reg_max.
Returns:
x (Tensor): Integral result of box locations, i.e., distance
offsets from the box center in four directions, shape (N, 4).
"""
x = F.softmax(x.reshape(-1, self.reg_max + 1), dim=1)
x = F.linear(x, self.project).reshape(-1, 4)
return x
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:17,
示例10: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x, lens, hidden=None):
emb_x = self.dp1(self.emb(x))
if not self.training:
self.rnn.flatten_parameters()
packed = nn.utils.rnn.pack_padded_sequence(
emb_x, lens, batch_first=True, enforce_sorted=False)
# output: (seq_len, batch, hidden)
outputs, hidden = self.rnn(packed, hidden)
outputs, _ = nn.utils.rnn.pad_packed_sequence(
outputs, batch_first=True)
if self.emb_tying:
outputs = F.linear(self.dp2(outputs), self.emb.weight)
else:
outputs = self.trans(self.dp2(outputs))
return outputs, hidden
开发者ID:Alexander-H-Liu,项目名称:End-to-end-ASR-Pytorch,代码行数:17,代码来源:lm.py
示例11: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, input):
if self.masked_weight is None:
return F.linear(input, self.mask * self.weight, self.bias)
else:
# ~17% speedup for Prog Sampling.
return F.linear(input, self.masked_weight, self.bias)
开发者ID:naru-project,项目名称:naru,代码行数:8,
示例12: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x):
if self.groups == 1:
out = super(Linear, self).forward(x)
else:
x_g = x.chunk(self.groups, dim=-1)
w_g = self.weight.chunk(self.groups, dim=-1)
out = torch.cat([F.linear(x_g[i], w_g[i])
for i in range(self.groups)], -1)
if self.bias is not None:
out += self.bias
return out
开发者ID:nadavbh12,项目名称:Character-Level-Language-Modeling-with-Deeper-Self-Attention-pytorch,代码行数:13,
示例13: forward_no_cache
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward_no_cache(self, inputs):
"""Cost:
output = O(D^2N)
logabsdet = O(D)
where:
D = num of features
N = num of inputs
"""
lower, upper = self._create_lower_upper()
outputs = F.linear(inputs, upper)
outputs = F.linear(outputs, lower, self.bias)
logabsdet = self.logabsdet() * inputs.new_ones(outputs.shape[0])
return outputs, logabsdet
开发者ID:bayesiains,项目名称:nsf,代码行数:15,代码来源:lu.py
示例14: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, inputs, context=None):
if not self.training and self.using_cache:
self._check_forward_cache()
outputs = F.linear(inputs, self.cache.weight, self.bias)
logabsdet = self.cache.logabsdet * torch.ones(outputs.shape[0])
return outputs, logabsdet
else:
return self.forward_no_cache(inputs)
开发者ID:bayesiains,项目名称:nsf,代码行数:10,
示例15: inverse
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def inverse(self, inputs, context=None):
if not self.training and self.using_cache:
self._check_inverse_cache()
outputs = F.linear(inputs - self.bias, self.cache.inverse)
logabsdet = (-self.cache.logabsdet) * torch.ones(outputs.shape[0])
return outputs, logabsdet
else:
return self.inverse_no_cache(inputs)
开发者ID:bayesiains,项目名称:nsf,代码行数:10,
示例16: forward_no_cache
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward_no_cache(self, inputs):
"""Cost:
output = O(D^2N)
logabsdet = O(D^3)
where:
D = num of features
N = num of inputs
"""
batch_size = inputs.shape[0]
outputs = F.linear(inputs, self._weight, self.bias)
logabsdet = utils.logabsdet(self._weight)
logabsdet = logabsdet * torch.ones(batch_size)
return outputs, logabsdet
开发者ID:bayesiains,项目名称:nsf,代码行数:15,
示例17: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x):
return F.linear(x, self.weight * self.mask, self.bias)
开发者ID:bayesiains,项目名称:nsf,代码行数:4,
示例18: __init__
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def __init__(self,
in_degrees,
autoregressive_features,
context_features=None,
random_mask=False,
activation=F.relu,
dropout_probability=0.,
use_batch_norm=False):
super().__init__()
features = len(in_degrees)
# Batch norm.
if use_batch_norm:
self.batch_norm = nn.BatchNorm1d(features, eps=1e-3)
else:
self.batch_norm = None
if context_features is not None:
raise NotImplementedError()
# Masked linear.
self.linear = MaskedLinear(
in_degrees=in_degrees,
out_features=features,
autoregressive_features=autoregressive_features,
random_mask=random_mask,
is_output=False,
)
self.degrees = self.linear.degrees
# Activation and dropout.
self.activation = activation
self.dropout = nn.Dropout(p=dropout_probability)
开发者ID:bayesiains,项目名称:nsf,代码行数:35,
示例19: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x, init=False):
if init is True:
# out_features * in_features
self.V.data.copy_(torch.randn(self.V.data.size()).type_as(
self.V.data) * 0.05)
# norm is out_features * 1
v_norm = self.V.data / \
self.V.data.norm(2, 1).expand_as(self.V.data)
# batch_size * out_features
x_init = F.linear(x, Variable(v_norm)).data
# out_features
m_init, v_init = x_init.mean(0).squeeze(
0), x_init.var(0).squeeze(0)
# out_features
scale_init = self.init_scale / \
torch.sqrt(v_init + 1e-10)
self.g.data.copy_(scale_init)
self.b.data.copy_(-m_init * scale_init)
x_init = scale_init.view(1, -1).expand_as(x_init) \
* (x_init - m_init.view(1, -1).expand_as(x_init))
self.V_avg.copy_(self.V.data)
self.g_avg.copy_(self.g.data)
self.b_avg.copy_(self.b.data)
return Variable(x_init)
else:
V, g, b = get_vars_maybe_avg(self, ['V', 'g', 'b'],
self.training,
polyak_decay=self.polyak_decay)
# batch_size * out_features
x = F.linear(x, V)
scalar = g / torch.norm(V, 2, 1).squeeze(1)
x = scalar.view(1, -1).expand_as(x) * x + \
b.view(1, -1).expand_as(x)
return x
开发者ID:xiadingZ,项目名称:video-caption-openNMT.pytorch,代码行数:36,
示例20: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, features):
cosine = F.linear(F.normalize(features), F.normalize(self.weight))
return cosine
开发者ID:maciej-sypetkowski,项目名称:kaggle-rcic-1st,代码行数:5,
示例21: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, input):
weight = self.compute_weight(update=self.training)
return F.linear(input, weight, self.bias)
开发者ID:rtqichen,项目名称:residual-flows,代码行数:5,
示例22: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, input):
weight = self.compute_weight(update=False)
return F.linear(input, weight, self.bias)
开发者ID:rtqichen,项目名称:residual-flows,代码行数:5,
示例23: forward
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def forward(self, x, logpx=None):
y = F.linear(x, self.weight)
if logpx is None:
return y
else:
return y, logpx - self._logdetgrad
开发者ID:rtqichen,项目名称:residual-flows,代码行数:8,
示例24: linear_classifier
点赞 5
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import linear [as 别名]
def linear_classifier(x, param_dict):
"""
Classifier.
"""
return F.linear(x, param_dict['weight_mean'], param_dict['bias_mean'])
开发者ID:cambridge-mlg,项目名称:cnaps,代码行数:7,
注:本文中的torch.nn.functional.linear方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。
python get score gain_Python functional.linear方法代码示例相关推荐
- python max((1、2、3)*2)_Python functional.max_pool2d方法代码示例
本文整理汇总了Python中torch.nn.functional.max_pool2d方法的典型用法代码示例.如果您正苦于以下问题:Python functional.max_pool2d方法的具体 ...
- python os path isfile_Python path.isfile方法代码示例
本文整理汇总了Python中os.path.isfile方法的典型用法代码示例.如果您正苦于以下问题:Python path.isfile方法的具体用法?Python path.isfile怎么用?P ...
- python session模块_Python backend.set_session方法代码示例
本文整理汇总了Python中keras.backend.set_session方法的典型用法代码示例.如果您正苦于以下问题:Python backend.set_session方法的具体用法?Pyth ...
- python logistic步骤_Python api.Logit方法代码示例
本文整理汇总了Python中statsmodels.api.Logit方法的典型用法代码示例.如果您正苦于以下问题:Python api.Logit方法的具体用法?Python api.Logit怎么 ...
- python request microsoft graph_Python request.headers方法代码示例
本文整理汇总了Python中flask.request.headers方法的典型用法代码示例.如果您正苦于以下问题:Python request.headers方法的具体用法?Python reque ...
- python cv2模块imshow_Python cv2.imshow方法代码示例
本文整理汇总了Python中cv2.imshow方法的典型用法代码示例.如果您正苦于以下问题:Python cv2.imshow方法的具体用法?Python cv2.imshow怎么用?Python ...
- python iteritems函数_Python six.iteritems方法代码示例
本文整理汇总了Python中sklearn.externals.six.iteritems方法的典型用法代码示例.如果您正苦于以下问题:Python six.iteritems方法的具体用法?Pyth ...
- python中的scaler_Python preprocessing.MaxAbsScaler方法代码示例
本文整理汇总了Python中sklearn.preprocessing.MaxAbsScaler方法的典型用法代码示例.如果您正苦于以下问题:Python preprocessing.MaxAbsSc ...
- python管理工具ports_Python options.port方法代码示例
本文整理汇总了Python中tornado.options.port方法的典型用法代码示例.如果您正苦于以下问题:Python options.port方法的具体用法?Python options.p ...
最新文章
- linux 定时任务 crontab 报错 service command not found 解决方法
- oracle9i解密rewrap,ORACLE9I+DATAGUARD+RMAN
- MobaXterm无法退格删除,出现^H
- powerbuilder判断复选框是否选中_如何判断基金经理投资风格呢?方法仅供参考
- 典型微型计算机控制系统的实例,微型计算机控制系统概述.ppt
- 【C/C++】C++基本语法
- 金蝶云php webapi,K/3 Cloud Web API销售出库单PHP完整示例【分享】
- 易学入门书籍V8.7版
- 苹果怎么改字体_截图里的文字要改,字体怎么做到一模一样?
- 首届技术播客月开播在即
- 阿肯色大学计算机,阿肯色大学怎么样?
- Linux下cp和scp的详细说明及其他们的区别
- Java、Python、C++、PHP、JavaScript这5大编程语言,我究竟该选哪个?
- GPUImage实现人脸实时识别
- 使用虚拟主机安装cyberpanel面板并创建wordpress站点
- gem5 GPGPU-Sim 安装踩坑笔记
- linux修改英文设置密码,linux 如何修改passwd的密码 设置密码
- h5页面在微信中打开,字体显示不正常
- uboot代码解析1:根据目的找主线
- 武汉大学数据结构MOOC第2周测验
热门文章
- c combobox绑定mysql数据库_C# ComboBox:组合框控件数据绑定
- 服务器生成php文件夹下,PHP创建文件以供下载,而不在服务器上保存
- 基于JAVA+SpringMVC+Mybatis+MYSQL的族谱管理系统
- 【链接】Eclipse中快速打开文件所在的文件夹位置
- 【GISER Painter】矢量切片(Vector tile)番外一:Proj4js
- python基础之五大标准数据类型
- 邮件协议POP3/IMAP/SMTP服务的区别
- 网页中调用Google地图
- 碎裂效果尝试(clip-path篇)
- Why Not Specialize Function Templates?