本文整理汇总了Python中torch.round方法的典型用法代码示例。如果您正苦于以下问题:Python torch.round方法的具体用法?Python torch.round怎么用?Python torch.round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块torch的用法示例。
在下文中一共展示了torch.round方法的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: calc_region
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import round [as 别名]
def calc_region(bbox, ratio, featmap_size=None):
"""Calculate a proportional bbox region.
The bbox center are fixed and the new h' and w' is h * ratio and w * ratio.
Args:
bbox (Tensor): Bboxes to calculate regions, shape (n, 4).
ratio (float): Ratio of the output region.
featmap_size (tuple): Feature map size used for clipping the boundary.
Returns:
tuple: x1, y1, x2, y2
"""
x1 = torch.round((1 - ratio) * bbox[0] + ratio * bbox[2]).long()
y1 = torch.round((1 - ratio) * bbox[1] + ratio * bbox[3]).long()
x2 = torch.round(ratio * bbox[0] + (1 - ratio) * bbox[2]).long()
y2 = torch.round(ratio * bbox[1] + (1 - ratio) * bbox[3]).long()
if featmap_size is not None:
x1 = x1.clamp(min=0, max=featmap_size[1])
y1 = y1.clamp(min=0, max=featmap_size[0])
x2 = x2.clamp(min=0, max=featmap_size[1])
y2 = y2.clamp(min=0, max=featmap_size[0])
return (x1, y1, x2, y2)
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:25,
示例2: calc_region
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import round [as 别名]
def calc_region(bbox, ratio, featmap_size=None):
"""Calculate a proportional bbox region.
The bbox center are fixed and the new h' and w' is h * ratio and w * ratio.
Args:
bbox (Tensor): Bboxes to calculate regions, shape (n, 4)
ratio (float): Ratio of the output region.
featmap_size (tuple): Feature map size used for clipping the boundary.
Returns:
tuple: x1, y1, x2, y2
"""
x1 = torch.round((1 - ratio) * bbox[0] + ratio * bbox[2]).long()
y1 = torch.round((1 - ratio) * bbox[1] + ratio * bbox[3]).long()
x2 = torch.round(ratio * bbox[0] + (1 - ratio) * bbox[2]).long()
y2 = torch.round(ratio * bbox[1] + (1 - ratio) * bbox[3]).long()
if featmap_size is not None:
x1 = x1.clamp(min=0, max=featmap_size[1] - 1)
y1 = y1.clamp(min=0, max=featmap_size[0] - 1)
x2 = x2.clamp(min=0, max=featmap_size[1] - 1)
y2 = y2.clamp(min=0, max=featmap_size[0] - 1)
return (x1, y1, x2, y2)
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:25,
示例3: crop
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import round [as 别名]
def crop(self, box):
assert isinstance(box, (list, tuple, torch.Tensor)), str(type(box))
# box is assumed to be xyxy
current_width, current_height = self.size
xmin, ymin, xmax, ymax = [round(float(b)) for b in box]
assert xmin <= xmax and ymin <= ymax, str(box)
xmin = min(max(xmin, 0), current_width - 1)
ymin = min(max(ymin, 0), current_height - 1)
xmax = min(max(xmax, 0), current_width)
ymax = min(max(ymax, 0), current_height)
xmax = max(xmax, xmin + 1)
ymax = max(ymax, ymin + 1)
width, height = xmax - xmin, ymax - ymin
cropped_parsing = self.parsing[:, ymin:ymax, xmin:xmax]
cropped_size = width, height
return Parsing(cropped_parsing, cropped_size)
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:22,
示例4: parsing_on_boxes
点赞 6
# 需要导入模块: import torch [as 别名]
# 或者: from torch import round [as 别名]
def parsing_on_boxes(parsing, rois, heatmap_size):
device = rois.device
rois = rois.to(torch.device("cpu"))
parsing_list = []
for i in range(rois.shape[0]):
parsing_ins = parsing[i].cpu().numpy()
xmin, ymin, xmax, ymax = torch.round(rois[i]).int()
cropped_parsing = parsing_ins[ymin:ymax, xmin:xmax]
resized_parsing = cv2.resize(
cropped_parsing,
(heatmap_size[1], heatmap_size[0]),
interpolation=cv2.INTER_NEAREST
)
parsing_list.append(torch.from_numpy(resized_parsing))
if len(parsing_list) == 0: