当前位置: 首页>>代码示例>>Python>>正文


Python ops.roi_align方法代码示例

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


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

示例1: forward

# 需要导入模块: from torchvision import ops [as 别名]
# 或者: from torchvision.ops import roi_align [as 别名]
def forward(self, features, rois):
        """
        Args:
            features: NCHW images
            rois: Bx5 boxes. First column is the index into N. The other 4
            columns are xyxy.
        """
        assert rois.dim() == 2 and rois.size(1) == 5

        if self.use_torchvision:
            from torchvision.ops import roi_align as tv_roi_align
            return tv_roi_align(features, rois, self.out_size,
                                self.spatial_scale, self.sample_num)
        else:
            return roi_align(features, rois, self.out_size, self.spatial_scale,
                             self.sample_num, self.aligned) 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:18,代码来源:roi_align.py

示例2: forward

# 需要导入模块: from torchvision import ops [as 别名]
# 或者: from torchvision.ops import roi_align [as 别名]
def forward(self, x):
        x, rois, sequences = x
        _, _, input_h, input_w = x.shape
        x_l1, x_l2 = self.base(x)
        dtype = x_l1.dtype
        rois = [roi.to(dtype) for roi in rois]
        del x
        x_l1 = roi_align(
            x_l1, rois,
            output_size=(self.res_l1, self.res_l1),
            spatial_scale=x_l1.shape[3] / input_w,
        )
        x_l2 = roi_align(
            x_l2, rois,
            output_size=(self.res_l2, self.res_l2),
            spatial_scale=x_l2.shape[3] / input_w,
        )
        x = torch.cat(
            [x_l1.flatten(start_dim=1),
             x_l2.flatten(start_dim=1)],
            dim=1)
        x, x_features = self.head(x)
        if self.use_sequences:  # unused
            x_features = self._apply_lstm(x_features, rois, sequences)
            x = self.head.apply_fc_out(x_features)
        return x, x_features, rois 
开发者ID:lopuhin,项目名称:kaggle-kuzushiji-2019,代码行数:28,代码来源:models.py

示例3: get_yolo_feature_vec

# 需要导入模块: from torchvision import ops [as 别名]
# 或者: from torchvision.ops import roi_align [as 别名]
def get_yolo_feature_vec(self, coords):
        feature_map = self.get_feature_map()
        ratio = self.img_size/feature_map.size()[2]
        #coords = (10,10,100,100)
        coords = torch.cat((torch.Tensor([0]),torch.Tensor(coords))).view(1,5).cuda()
        #coords = torch.Tensor(coords).view(1,4).cuda()
        #print(feature_map.shape)
        #print(coords.shape)
        #print(coords.shape)
        with torch.no_grad():
            roi = roi_align(  feature_map, coords,(3,3) , spatial_scale=1/ratio)
        #print(roi)
        vec = F.adaptive_avg_pool2d(roi, (1, 1))
        return np.squeeze(vec.cpu().detach().numpy()) 
开发者ID:simaiden,项目名称:Clothing-Detection,代码行数:16,代码来源:models.py

示例4: project_masks_on_boxes

# 需要导入模块: from torchvision import ops [as 别名]
# 或者: from torchvision.ops import roi_align [as 别名]
def project_masks_on_boxes(gt_masks, boxes, matched_idxs, M):
    """
    Given segmentation masks and the bounding boxes corresponding
    to the location of the masks in the image, this function
    crops and resizes the masks in the position defined by the
    boxes. This prepares the masks for them to be fed to the
    loss computation as the targets.
    """
    matched_idxs = matched_idxs.to(boxes)
    rois = torch.cat([matched_idxs[:, None], boxes], dim=1)
    gt_masks = gt_masks[:, None].to(rois)
    return roi_align(gt_masks, rois, (M, M), 1)[:, 0] 
开发者ID:lopuhin,项目名称:kaggle-kuzushiji-2019,代码行数:14,代码来源:roi_heads.py

示例5: forward

# 需要导入模块: from torchvision import ops [as 别名]
# 或者: from torchvision.ops import roi_align [as 别名]
def forward(self, features, rois):
        if self.use_torchvision:
            from torchvision.ops import roi_align as tv_roi_align
            return tv_roi_align(features, rois, self.out_size,
                                self.spatial_scale, self.sample_num)
        else:
            return roi_align(features, rois, self.out_size, self.spatial_scale,
                             self.sample_num) 
开发者ID:xieenze,项目名称:PolarMask,代码行数:10,代码来源:roi_align.py

示例6: forward

# 需要导入模块: from torchvision import ops [as 别名]
# 或者: from torchvision.ops import roi_align [as 别名]
def forward(self, features, rois):
        if self.use_torchvision:
            from torchvision.ops import roi_align as tv_roi_align
            return tv_roi_align(features, rois, _pair(self.out_size),
                                self.spatial_scale, self.sample_num)
        else:
            return roi_align(features, rois, self.out_size, self.spatial_scale,
                             self.sample_num) 
开发者ID:lizhe960118,项目名称:CenterNet,代码行数:10,代码来源:roi_align.py


注:本文中的torchvision.ops.roi_align方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。