本文整理匯總了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)
示例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
示例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())
示例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]
示例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)
示例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)