本文整理汇总了Python中torch.ne方法的典型用法代码示例。如果您正苦于以下问题:Python torch.ne方法的具体用法?Python torch.ne怎么用?Python torch.ne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch
的用法示例。
在下文中一共展示了torch.ne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: intersectionAndUnion
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def intersectionAndUnion(batch_data, pred, numClass):
(imgs, segs, infos) = batch_data
_, preds = torch.max(pred.data.cpu(), dim=1)
# compute area intersection
intersect = preds.clone()
intersect[torch.ne(preds, segs)] = -1
area_intersect = torch.histc(intersect.float(),
bins=numClass,
min=0,
max=numClass - 1)
# compute area union:
preds[torch.lt(segs, 0)] = -1
area_pred = torch.histc(preds.float(),
bins=numClass,
min=0,
max=numClass - 1)
area_lab = torch.histc(segs.float(),
bins=numClass,
min=0,
max=numClass - 1)
area_union = area_pred + area_lab - area_intersect
return area_intersect, area_union
示例2: _augmented_scores
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def _augmented_scores(self, s, y):
if self._range is None:
delattr(self, '_range')
self.register_buffer('_range', torch.arange(s.size(1), device=s.device)[None, :])
delta = torch.ne(y[:, None], self._range).detach().float()
return s + delta - s.gather(1, y[:, None])
示例3: nNanElement
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def nNanElement(x):
return torch.sum(torch.ne(x, x).float())
示例4: getNanMask
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def getNanMask(x):
return torch.ne(x, x)
示例5: forward
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def forward(self, outputs, target, cout, epoch_num, inputs, *args):
val_pixels = torch.ne(target, 0).float().cuda()
err = F.smooth_l1_loss(outputs*val_pixels, target*val_pixels, reduction='none')
val_pixels = torch.ne(inputs, 0).float().cuda()
inp_loss = F.smooth_l1_loss(outputs*val_pixels, inputs*val_pixels, reduction='none')
loss = err + 0.1 * inp_loss
return torch.mean(loss)
示例6: navg_forward
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def navg_forward(self, navg, c, x, b, eps=1e-20, restore=False):
# Normalized Averaging
ca = navg(c)
xout = torch.div(navg(x*c), ca + eps)
# Add bias
sz = b.size(0)
b = b.view(1,sz,1,1)
b = b.expand_as(xout)
xout = xout + b
if restore:
cm = (c == 0).float()
xout = torch.mul(xout, cm) + torch.mul(1-cm, x)
# Propagate confidence
#cout = torch.ne(ca, 0).float()
cout = ca
sz = cout.size()
cout = cout.view(sz[0], sz[1], -1)
k = navg.weight
k_sz = k.size()
k = k.view(k_sz[0], -1)
s = torch.sum(k, dim=-1, keepdim=True)
cout = cout / s
cout = cout.view(sz)
k = k.view(k_sz)
return xout, cout
示例7: process_data
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def process_data(self, batch):
text1 = torch.LongTensor(batch['text1']).to(self.device)
text2 = torch.LongTensor(batch['text2']).to(self.device)
mask1 = torch.ne(text1, self.args.padding).unsqueeze(2)
mask2 = torch.ne(text2, self.args.padding).unsqueeze(2)
inputs = {
'text1': text1,
'text2': text2,
'mask1': mask1,
'mask2': mask2,
}
if 'target' in batch:
target = torch.LongTensor(batch['target']).to(self.device)
return inputs, target
return inputs, None
示例8: pck
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def pck(source_points,warped_points,L_pck,alpha=0.1):
# compute precentage of correct keypoints
batch_size=source_points.size(0)
pck=torch.zeros((batch_size))
for i in range(batch_size):
p_src = source_points[i,:]
p_wrp = warped_points[i,:]
N_pts = torch.sum(torch.ne(p_src[0,:],-1)*torch.ne(p_src[1,:],-1))
point_distance = torch.pow(torch.sum(torch.pow(p_src[:,:N_pts]-p_wrp[:,:N_pts],2),0),0.5)
L_pck_mat = L_pck[i].expand_as(point_distance)
correct_points = torch.le(point_distance,L_pck_mat*alpha)
pck[i]=torch.mean(correct_points.float())
return pck
示例9: mean_dist
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def mean_dist(source_points,warped_points,L_pck):
# compute precentage of correct keypoints
batch_size=source_points.size(0)
dist=torch.zeros((batch_size))
for i in range(batch_size):
p_src = source_points[i,:]
p_wrp = warped_points[i,:]
N_pts = torch.sum(torch.ne(p_src[0,:],-1)*torch.ne(p_src[1,:],-1))
point_distance = torch.pow(torch.sum(torch.pow(p_src[:,:N_pts]-p_wrp[:,:N_pts],2),0),0.5)
L_pck_mat = L_pck[i].expand_as(point_distance)
dist[i]=torch.mean(torch.div(point_distance,L_pck_mat))
return dist
示例10: encode
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def encode(self, features):
seq = features["inputs"]
pred = features["preds"]
mask = torch.ne(seq, 0).float().cuda()
enc_attn_bias = self.masking_bias(mask)
inputs = torch.nn.functional.embedding(seq, self.embedding)
if "embedding" in features and not self.training:
embedding = features["embedding"]
unk_mask = features["mask"].to(mask)[:, :, None]
inputs = inputs * unk_mask + (1.0 - unk_mask) * embedding
preds = torch.nn.functional.embedding(pred, self.weights)
inputs = torch.cat([inputs, preds], axis=-1)
inputs = inputs * (self.hidden_size ** 0.5)
inputs = inputs + self.bias
inputs = nn.functional.dropout(self.encoding(inputs), self.dropout,
self.training)
enc_attn_bias = enc_attn_bias.to(inputs)
encoder_output = self.encoder(inputs, enc_attn_bias)
logits = self.classifier(encoder_output)
return logits
示例11: forward
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def forward(self, features, labels):
mask = torch.ne(features["inputs"], 0).float().cuda()
logits = self.encode(features)
loss = self.criterion(logits, labels)
mask = mask.to(logits)
return torch.sum(loss * mask) / torch.sum(mask)
示例12: delta
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def delta(y, labels, alpha=None):
"""
Compute zero-one loss matrix for a vector of ground truth y
"""
if isinstance(y, ag.Variable):
labels = ag.Variable(labels, requires_grad=False)
delta = torch.ne(y[:, None], labels[None, :]).float()
if alpha is not None:
delta = alpha * delta
return delta
示例13: split
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def split(x, y, labels):
labels = ag.Variable(labels, requires_grad=False)
mask = torch.ne(labels[None, :], y[:, None])
# gather result:
# x_1: all scores that do contain the ground truth
x_1 = x[mask].view(x.size(0), -1)
# x_2: scores of the ground truth
x_2 = x.gather(1, y[:, None]).view(-1)
return x_1, x_2
示例14: loss
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def loss(self, x, sent_lengths, pos, rel, y):
mask = torch.ne(x, self.pad_index)
emissions = self.lstm_forward(x, pos, rel, sent_lengths)
return self.crflayer(emissions, y, mask=mask)
示例15: forward
# 需要导入模块: import torch [as 别名]
# 或者: from torch import ne [as 别名]
def forward(self, x, poses, rels, sent_lengths):
mask = torch.ne(x, self.pad_index)
emissions = self.lstm_forward(x, poses, rels, sent_lengths)
return self.crflayer.decode(emissions, mask=mask)