python中floor_Python torch.floor方法代码示例

本文详细介绍了Python中torch.floor函数的用途,并通过21个代码示例展示了如何使用该方法,包括在RoI映射、数据处理、图像处理等场景中的应用。这些示例覆盖了不同的项目和库,如mmdetection、AerialDetection和yolo2-pytorch等。
摘要由CSDN通过智能技术生成

本文整理汇总了Python中torch.floor方法的典型用法代码示例。如果您正苦于以下问题:Python torch.floor方法的具体用法?Python torch.floor怎么用?Python torch.floor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块torch的用法示例。

在下文中一共展示了torch.floor方法的21个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: map_roi_levels

​点赞 6

# 需要导入模块: import torch [as 别名]

# 或者: from torch import floor [as 别名]

def map_roi_levels(self, rois, num_levels):

"""Map rois to corresponding feature levels by scales.

- scale < finest_scale * 2: level 0

- finest_scale * 2 <= scale < finest_scale * 4: level 1

- finest_scale * 4 <= scale < finest_scale * 8: level 2

- scale >= finest_scale * 8: level 3

Args:

rois (Tensor): Input RoIs, shape (k, 5).

num_levels (int): Total level number.

Returns:

Tensor: Level index (0-based) of each RoI, shape (k, )

"""

scale = torch.sqrt(

(rois[:, 3] - rois[:, 1]) * (rois[:, 4] - rois[:, 2]))

target_lvls = torch.floor(torch.log2(scale / self.finest_scale + 1e-6))

target_lvls = target_lvls.clamp(min=0, max=num_levels - 1).long()

return target_lvls

开发者ID:open-mmlab,项目名称:mmdetection,代码行数:22,

示例2: map_roi_levels

​点赞 6

# 需要导入模块: import torch [as 别名]

# 或者: from torch import floor [as 别名]

def map_roi_levels(self, rois, num_levels):

"""Map rois to corresponding feature levels by scales.

- scale < finest_scale: level 0

- finest_scale <= scale < finest_scale * 2: level 1

- finest_scale * 2 <= scale < finest_scale * 4: level 2

- scale >= finest_scale * 4: level 3

Args:

rois (Tensor): Input RoIs, shape (k, 5).

num_levels (int): Total level number.

Returns:

Tensor: Level index (0-based) of each RoI, shape (k, )

"""

scale = torch.sqrt(

(rois[:, 3] - rois[:, 1] + 1) * (rois[:, 4] - rois[:, 2] + 1))

target_lvls = torch.floor(torch.log2(scale / self.finest_scale + 1e-6))

target_lvls = target_lvls.clamp(min=0, max=num_levels - 1).long()

return target_lvls

开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:22,

示例3: map_roi_levels

​点赞 6

# 需要导入模块: import torch [as 别名]

# 或者: from torch import floor [as 别名]

def map_roi_levels(self, rois, num_levels):

"""Map rrois to corresponding feature levels by scales.

- scale < finest_scale: level 0

- finest_scale <= scale < finest_scale * 2: level 1

- finest_scale * 2 <= scale < finest_scale * 4: level 2

- scale >= finest_scale * 4: level 3

Args:

rois (Tensor): Input RRoIs, shape (k, 6). (index, x, y, w, h, angle)

num_levels (int): Total level number.

Returns:

Tensor: Level index (0-based) of each RoI, shape (k, )

"""

scale = torch.sqrt(rois[:, 3] * rois[:, 4])

target_lvls = torch.floor(torch.log2(scale / self.finest_scale + 1e-6))

target_lvls = target_lvls.clamp(min=0, max=num_levels - 1).long()

return target_lvls

开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:21,

示例4: fit_positive

​点赞 6

# 需要导入模块: import torch [as 别名]

# 或者: from torch import floor [as 别名]

def fit_positive(rows, cols, yx_min, yx_max, anchors):

device_id = anchors.get_device() if torch.cuda.is_available() else None

batch_size, num, _ = yx_min.size()

num_anchors, _ = anchors.size()

valid = torch.prod(yx_min < yx_max, -1)

center = (yx_min + yx_max) / 2

ij = torch.floor(center)

i, j = torch.unbind(ij.long(), -1)

index = i * cols + j

anchors2 = anchors / 2

iou_matrix = utils.iou.torch.iou_matrix((yx_min - center).view(-1, 2), (yx_max - center).view(-1, 2), -anchors2, anchors2).view(batch_size, -1, num_anchors)

iou, index_anchor = iou_matrix.max(-1)

_positive = []

cells = rows * cols

for valid, index, index_anchor in zip(torch.unbind(valid), torch.unbind(index), torch.unbind(index_anchor)):

index, index_anchor = (t[valid] for t in (index, index_anchor))

t = utils.ensure_device(to

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值