コード例 #1
0
 def gather_pool_logits(pool, logits):
   from detectron2.utils import comm
   pool_list = comm.gather(data=pool)
   logits_list = comm.gather(data=logits)
   if len(pool_list) > 0:
     pool = torch.cat(pool_list, dim=0).to('cuda')
   if len(logits_list) > 0:
     logits = torch.cat(logits_list, dim=0).to('cuda')
   return pool, logits
コード例 #2
0
def get_sample_imgs_list_ddp(sample_func,
                             num_imgs=50000,
                             as_numpy=True,
                             stdout=sys.stdout):
    """

  :param sample_func:
  :param num_imgs:
  :param stdout:
  :return:
  """
    import torch
    from template_lib.d2.utils import comm

    ws = comm.get_world_size()
    num_imgs = num_imgs // ws
    imgs = get_sample_imgs_list(sample_func=sample_func,
                                num_imgs=num_imgs,
                                as_numpy=as_numpy,
                                stdout=stdout)

    imgs_list = comm.gather(imgs)
    if len(imgs_list) > 0:
        if as_numpy:
            imgs = np.concatenate(imgs_list, axis=0)
        else:
            imgs = torch.cat(imgs_list, dim=0)
    return imgs
コード例 #3
0
 def _gather_data(self, data, is_numpy=False):
     data_list = comm.gather(data=data)
     if len(data_list) > 0:
         if is_numpy:
             data = np.concatenate(data_list, axis=0)
         else:
             data = torch.cat(data_list, dim=0).to('cuda')
     return data
コード例 #4
0
ファイル: utils.py プロジェクト: gengcong940126/template_lib
def gather_tensor(data):
    from template_lib.d2.utils import comm

    data_list = comm.gather(data=data)
    if len(data_list) > 0:
        if isinstance(data, np.ndarray):
            data = np.concatenate(data_list, axis=0)
        else:
            data = torch.cat(data_list, dim=0).to(device=data.device)
    else:
        data = None
    return data
コード例 #5
0
 def _gather_numpy_array(self, data):
   data_list = comm.gather(data=data)
   if len(data_list) > 0:
     data = np.concatenate(data_list, axis=0)
   return data