本文整理汇总了Python中torch.abs方法的典型用法代码示例。如果您正苦于以下问题:Python torch.abs方法的具体用法?Python torch.abs怎么用?Python torch.abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块torch的用法示例。
在下文中一共展示了torch.abs方法的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_uncertainty
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import abs [as 别名]
def _get_uncertainty(self, mask_pred, labels):
"""Estimate uncertainty based on pred logits.
We estimate uncertainty as L1 distance between 0.0 and the logits
prediction in 'mask_pred' for the foreground class in `classes`.
Args:
mask_pred (Tensor): mask predication logits, shape (num_rois,
num_classes, mask_height, mask_width).
labels (list[Tensor]): Either predicted or ground truth label for
each predicted mask, of length num_rois.
Returns:
scores (Tensor): Uncertainty scores with the most uncertain
locations having the highest uncertainty score,
shape (num_rois, 1, mask_height, mask_width)
"""
if mask_pred.shape[1] == 1:
gt_class_logits = mask_pred.clone()
else:
inds = torch.arange(mask_pred.shape[0], device=mask_pred.device)
gt_class_logits = mask_pred[inds, labels].unsqueeze(1)
return -torch.abs(gt_class_logits)
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:26,
示例2: smooth_l1_loss
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import abs [as 别名]
def smooth_l1_loss(pred, target, beta=1.0):
"""Smooth L1 loss.
Args:
pred (torch.Tensor): The prediction.
target (torch.Tensor): The learning target of the prediction.
beta (float, optional): The threshold in the piecewise function.
Defaults to 1.0.
Returns:
torch.Tensor: Calculated loss
"""
assert beta > 0
assert pred.size() == target.size() and target.numel() > 0
diff = torch.abs(pred - target)
loss = torch.where(diff < beta, 0.5 * diff * diff / beta,
diff - 0.5 * beta)
return loss
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:20,
示例3: plot_examples
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import abs [as 别名]
def plot_examples(data_loader, model, epoch, plotter, ind = [0, 10, 20]):
# switch to evaluate mode
model.eval()
for i, (g, h, e, target) in enumerate(data_loader):
if i in ind:
subfolder_path = 'batch_' + str(i) + '_t_' + str(int(target[0][0])) + '/epoch_' + str(epoch) + '/'
if not os.path.isdir(args.plotPath + subfolder_path):
os.makedirs(args.plotPath + subfolder_path)
num_nodes = torch.sum(torch.sum(torch.abs(h[0, :, :]), 1) > 0)
am = g[0, 0:num_nodes, 0:num_nodes].numpy()
pos = h[0, 0:num_nodes, :].numpy()
plotter.plot_graph(am, position=pos, fig_name=subfolder_path+str(i) + '_input.png')
# Prepare input data
if args.cuda:
g, h, e, target = g.cuda(), h.cuda(), e.cuda(), target.cuda()
g, h, e, target = Variable(g), Variable(h), Variable(e), Variable(target)
# Compute output
model(g, h, e, lambda cls, id: plotter.plot_graph(am, position=pos, cls=cls,
fig_name=subfolder_path+ id))
开发者ID:priba,项目名称:nmp_qc,代码行数:27,
示例4: forward
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import abs [as 别名]
def forward(self, images):
"""Extract image feature vectors."""
features = self.cnn(images)
# normalization in the image embedding space
features = l2norm(features)
# linear projection to the joint embedding space
features = self.fc(features)
# normalization in the joint embedding space
if not self.no_imgnorm:
features = l2norm(features)
# take the absolute value of the embedding (used in order embeddings)
if self.use_abs:
features = torch.abs(features)
return features
开发者ID:ExplorerFreda,项目名称:VSE-C,代码行数:21,
示例5: _smooth_l1_loss
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import abs [as 别名]