本文整理汇总了Python中torch.utils.data.permute方法的典型用法代码示例。如果您正苦于以下问题:Python data.permute方法的具体用法?Python data.permute怎么用?Python data.permute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch.utils.data
的用法示例。
在下文中一共展示了data.permute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getitem__
# 需要导入模块: from torch.utils import data [as 别名]
# 或者: from torch.utils.data import permute [as 别名]
def __getitem__(self, index):
# get the anchor index for current sample index
# here we set the anchor index to the last one
# sample in this group
minibatch_db = [self._roidb[index]] # [self._roidb[index_ratio]]
blobs = get_minibatch(minibatch_db, self._num_classes)
np.random.shuffle(blobs['rois'])
rois = torch.from_numpy(blobs['rois'][:self.max_rois_size])
data = torch.from_numpy(blobs['data'])
labels = torch.from_numpy(blobs['labels'])
data_height, data_width = data.size(1), data.size(2)
data = data.permute(0, 3, 1, 2).contiguous().view(3, data_height, data_width)
info = torch.Tensor([rois.size(0), data_height, data_width])
return data, rois, labels, info
示例2: __getitem__
# 需要导入模块: from torch.utils import data [as 别名]
# 或者: from torch.utils.data import permute [as 别名]
def __getitem__(self, index):
indexes = [index]
blobs = self.get_one_sample(indexes)
data = torch.from_numpy(blobs['data'])
im_info = torch.from_numpy(blobs['im_info'])
mem_size = torch.from_numpy(blobs['memory_size'])
# we need to random shuffle the bounding box.
data_height, data_width = data.size(1), data.size(2)
if self.phase == 'train':
# if the number of region is greater than 100 then random pick 100 regions
# this opt can make the used memory of GPUs more stable.
# only for train and val phase
np.random.shuffle(blobs['gt_boxes'])
if blobs['gt_boxes'].shape[0] > 100:
print('sampling regions from %d to %d' % (blobs['gt_boxes'].shape[0], 100))
blobs['gt_boxes'] = blobs['gt_boxes'][:100]
elif self.phase == 'eval':
# np.random.shuffle(blobs['gt_boxes'])
if blobs['gt_boxes'].shape[0] > 100:
print('sampling regions from %d to %d' % (blobs['gt_boxes'].shape[0], 100))
blobs['gt_boxes'] = blobs['gt_boxes'][:100]
else:
pass
# if self.args.with_global:
# Arr_ = self._get_adjmat_Arr(blobs['gt_boxes']) # 5*r*r
# Arr = torch.from_numpy(Arr_)
# else:
# Arr = 0.
gt_boxes = torch.from_numpy(blobs['gt_boxes'])
# permute trim_data to adapt to downstream processing
data = data.permute(0, 3, 1, 2).contiguous().view(3, data_height, data_width)
im_info = im_info.view(3)
return data, im_info, gt_boxes, mem_size, blobs['data'], blobs['gt_boxes']