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


Python data.permute方法代码示例

本文整理汇总了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 
开发者ID:jd730,项目名称:OICR-pytorch,代码行数:19,代码来源:roibatchLoader.py

示例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'] 
开发者ID:coderSkyChen,项目名称:Iterative-Visual-Reasoning.pytorch,代码行数:38,代码来源:batchLoader.py


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