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


Python ndarray.transpose方法代码示例

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


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

示例1: load_bin

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def load_bin(path, image_size):
  try:
    with open(path, 'rb') as f:
      bins, issame_list = pickle.load(f) #py2
  except UnicodeDecodeError as e:
    with open(path, 'rb') as f:
      bins, issame_list = pickle.load(f, encoding='bytes') #py3
  data_list = []
  for flip in [0,1]:
    data = nd.empty((len(issame_list)*2, 3, image_size[0], image_size[1]))
    data_list.append(data)
  for i in range(len(issame_list)*2):
    _bin = bins[i]
    img = mx.image.imdecode(_bin)
    if img.shape[1]!=image_size[0]:
      img = mx.image.resize_short(img, image_size[0])
    img = nd.transpose(img, axes=(2, 0, 1))
    for flip in [0,1]:
      if flip==1:
        img = mx.ndarray.flip(data=img, axis=2)
      data_list[flip][i][:] = img
    if i%1000==0:
      print('loading bin', i)
  print(data_list[0].shape)
  return (data_list, issame_list) 
开发者ID:deepinsight,项目名称:insightface,代码行数:27,代码来源:verification.py

示例2: load_dataset

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def load_dataset(lfw_dir, image_size):
  lfw_pairs = read_pairs(os.path.join(lfw_dir, 'pairs.txt'))
  lfw_paths, issame_list = get_paths(lfw_dir, lfw_pairs, 'jpg')
  lfw_data_list = []
  for flip in [0,1]:
    lfw_data = nd.empty((len(lfw_paths), 3, image_size[0], image_size[1]))
    lfw_data_list.append(lfw_data)
  i = 0
  for path in lfw_paths:
    with open(path, 'rb') as fin:
      _bin = fin.read()
      img = mx.image.imdecode(_bin)
      img = nd.transpose(img, axes=(2, 0, 1))
      for flip in [0,1]:
        if flip==1:
          img = mx.ndarray.flip(data=img, axis=2)
        lfw_data_list[flip][i][:] = img
      i+=1
      if i%1000==0:
        print('loading lfw', i)
  print(lfw_data_list[0].shape)
  print(lfw_data_list[1].shape)
  return (lfw_data_list, issame_list) 
开发者ID:deepinsight,项目名称:insightface,代码行数:25,代码来源:lfw.py

示例3: load_bin

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def load_bin(path, image_size):
  bins, issame_list = pickle.load(open(path, 'rb'))
  data_list = []
  for flip in [0,1]:
    data = nd.empty((len(issame_list)*2, 3, image_size[0], image_size[1]))
    data_list.append(data)
  for i in xrange(len(issame_list)*2):
    _bin = bins[i]
    img = mx.image.imdecode(_bin)
    if img.shape[1]!=image_size[0]:
      img = mx.image.resize_short(img, image_size[0])
    img = nd.transpose(img, axes=(2, 0, 1))
    for flip in [0,1]:
      if flip==1:
        img = mx.ndarray.flip(data=img, axis=2)
      data_list[flip][i][:] = img
    if i%1000==0:
      print('loading bin', i)
  print(data_list[0].shape)
  return (data_list, issame_list) 
开发者ID:deepinsight,项目名称:insightface,代码行数:22,代码来源:verification.py

示例4: create_neg

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def create_neg(self, neg_head):
        if neg_head:
            def fn(heads, relations, tails, num_chunks, chunk_size, neg_sample_size):
                hidden_dim = heads.shape[1]
                heads = heads.reshape(num_chunks, neg_sample_size, hidden_dim)
                heads = nd.transpose(heads, axes=(0, 2, 1))
                tmp = (tails * relations).reshape(num_chunks, chunk_size, hidden_dim)
                return nd.linalg_gemm2(tmp, heads)
            return fn
        else:
            def fn(heads, relations, tails, num_chunks, chunk_size, neg_sample_size):
                hidden_dim = heads.shape[1]
                tails = tails.reshape(num_chunks, neg_sample_size, hidden_dim)
                tails = nd.transpose(tails, axes=(0, 2, 1))
                tmp = (heads * relations).reshape(num_chunks, chunk_size, hidden_dim)
                return nd.linalg_gemm2(tmp, tails)
            return fn 
开发者ID:dmlc,项目名称:dgl,代码行数:19,代码来源:score_fun.py

示例5: load_dataset_bin

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def load_dataset_bin(self):
        name = 'lfw'
        path = os.path.join(self.lfw_dir, name+".bin")
        bins, issame_list = pickle.load(open(path, 'rb'))
        data_list = []
        for flip in [0,1]:
          data = nd.empty((len(issame_list)*2, 3, self.image_size[0], self.image_size[1]))
          data_list.append(data)
        for i in xrange(len(issame_list)*2):
          _bin = bins[i]
          img = mx.image.imdecode(_bin)
          img = nd.transpose(img, axes=(2, 0, 1))
          for flip in [0,1]:
            if flip==1:
              img = mx.ndarray.flip(data=img, axis=2)
            data_list[flip][i][:] = img
          if i%1000==0:
            print('loading bin', i)
        print(data_list[0].shape)
        return (data_list, issame_list) 
开发者ID:becauseofAI,项目名称:MobileFace,代码行数:22,代码来源:lfw_comparison_and_plot_roc.py

示例6: load_bin

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def load_bin(path, image_size):
    try:
        with open(path, 'rb') as f:
            bins, issame_list = pickle.load(f)  # py2
    except UnicodeDecodeError as e:
        with open(path, 'rb') as f:
            bins, issame_list = pickle.load(f, encoding='bytes')  # py3
    data_list = []
    for flip in [0, 1]:
        data = nd.empty((len(issame_list) * 2, 3, image_size[0], image_size[1]))
        data_list.append(data)
    for i in range(len(issame_list) * 2):
        _bin = bins[i]
        img = mx.image.imdecode(_bin)
        if img.shape[1] != image_size[0]:
            img = mx.image.resize_short(img, image_size[0])
        img = nd.transpose(img, axes=(2, 0, 1))
        for flip in [0, 1]:
            if flip == 1:
                img = mx.ndarray.flip(data=img, axis=2)
            data_list[flip][i][:] = img
        if i % 1000 == 0:
            print('loading bin', i)
    print(data_list[0].shape)
    return (data_list, issame_list) 
开发者ID:944284742,项目名称:1.FaceRecognition,代码行数:27,代码来源:verification.py

示例7: load_bin

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def load_bin(path, image_size):
  bins, issame_list = pickle.load(open(path, 'rb'), encoding='bytes')
  data_list = []
  for flip in [0,1]:
    data = nd.empty((len(issame_list)*2, 3, image_size[0], image_size[1]))
    data_list.append(data)
  for i in range(len(issame_list)*2):
    _bin = bins[i]
    img = mx.image.imdecode(_bin)
    img = nd.transpose(img, axes=(2, 0, 1))
    for flip in [0,1]:
      if flip==1:
        img = mx.ndarray.flip(data=img, axis=2)
      data_list[flip][i][:] = img
    if i%1000==0:
      print('loading bin', i)
  print(data_list[0].shape)
  return (data_list, issame_list) 
开发者ID:bleakie,项目名称:MaskInsightface,代码行数:20,代码来源:verification.py

示例8: _rearrange

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def _rearrange(raw, F, upscale_factor):
    # (N, C * r^2, H, W) -> (N, C, r^2, H, W)
    splitted = F.reshape(raw, shape=(0, -4, -1, upscale_factor**2, 0, 0))
    # (N, C, r^2, H, W) -> (N, C, r, r, H, W)
    unflatten = F.reshape(splitted, shape=(0, 0, -4, upscale_factor, upscale_factor, 0, 0))
    # (N, C, r, r, H, W) -> (N, C, H, r, W, r)
    swapped = F.transpose(unflatten, axes=(0, 1, 4, 2, 5, 3))
    # (N, C, H, r, W, r) -> (N, C, H*r, W*r)
    return F.reshape(swapped, shape=(0, 0, -3, -3)) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:11,代码来源:super_resolution.py

示例9: postprocess_data

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def postprocess_data(self, datum):
        """Final postprocessing step before image is loaded into the batch."""
        return nd.transpose(datum, axes=(2, 0, 1)) 
开发者ID:deepinsight,项目名称:insightocr,代码行数:5,代码来源:data.py

示例10: next

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def next(self):
        """Returns the next batch of data."""
        #print('next')
        batch_size = self.batch_size
        batch_data = nd.empty((batch_size,)+self.data_shape)
        batch_label = nd.empty((batch_size,)+self.label_shape)
        i = 0
        #self.cutoff = random.randint(800,1280)
        try:
            while i < batch_size:
                #print('N', i)
                data, label = self.next_sample()
                data = nd.array(data)
                data = nd.transpose(data, axes=(2, 0, 1))
                label = nd.array(label)
                label = nd.transpose(label, axes=(2, 0, 1))
                batch_data[i][:] = data
                batch_label[i][:] = label
                i += 1
        except StopIteration:
            if i<batch_size:
                raise StopIteration

        #return {self.data_name  :  batch_data,
        #        self.label_name :  batch_label}
        #print(batch_data.shape, batch_label.shape)
        return mx.io.DataBatch([batch_data], [batch_label, self.weight_mask], batch_size - i) 
开发者ID:deepinsight,项目名称:insightface,代码行数:29,代码来源:data.py

示例11: batched_l2_dist

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def batched_l2_dist(a, b):
    a_squared = nd.power(nd.norm(a, axis=-1), 2)
    b_squared = nd.power(nd.norm(b, axis=-1), 2)

    squared_res = nd.add(nd.linalg_gemm(
        a, nd.transpose(b, axes=(0, 2, 1)), nd.broadcast_axes(nd.expand_dims(b_squared, axis=-2), axis=1, size=a.shape[1]), alpha=-2
    ), nd.expand_dims(a_squared, axis=-1))
    res = nd.sqrt(nd.clip(squared_res, 1e-30, np.finfo(np.float32).max))
    return res 
开发者ID:dmlc,项目名称:dgl,代码行数:11,代码来源:score_fun.py

示例12: load_dataset

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def load_dataset(self):
        lfw_pairs = self.read_pairs(os.path.join(self.lfw_dir, 'pairs.txt'))
        lfw_paths, issame_list = self.get_paths(self.lfw_dir, lfw_pairs, 'jpg')
        lfw_data_list = []
        for flip in [0,1]:
          # lfw_data = nd.empty((len(lfw_paths), 3, image_size[0], image_size[1]))
          lfw_data = nd.empty((len(lfw_paths), 1, 100, 100))
          lfw_data_list.append(lfw_data)
        i = 0
        for path in lfw_paths:
          with open(path, 'rb') as fin:           
            _bin = fin.read()
            img = np.asarray(bytearray(_bin), dtype="uint8")
            img = cv2.imdecode(img, 0) # (100, 100)
            img = img.reshape((1, img.shape[0], img.shape[1])) # (1, 100, 100)
            #img = nd.transpose(img, axes=(2, 0, 1)) # (1L, 100L, 100L)
            img = mx.nd.array(img) # (1L, 100L, 100L)
            for flip in [0,1]:
              if flip==1:
                img = mx.ndarray.flip(data=img, axis=2)
              lfw_data_list[flip][i][:] = img
            i+=1
            if i%1000==0:
              print('loading lfw', i)
        print(lfw_data_list[0].shape)
        print(lfw_data_list[1].shape)
        return (lfw_data_list, issame_list) 
开发者ID:becauseofAI,项目名称:MobileFace,代码行数:29,代码来源:lfw_comparison_and_plot_roc.py

示例13: predict

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def predict(self,img):
        img = nd.array(img)
        #print(img.shape)
        img = nd.transpose(img, axes=(2, 0, 1)).astype('float32')
        img = nd.expand_dims(img, axis=0)
        #print(img.shape)
        db = mx.io.DataBatch(data=(img,))

        self.model.forward(db, is_train=False)
        net_out = self.model.get_outputs()
        embedding = net_out[0].asnumpy()
        embedding = sklearn.preprocessing.normalize(embedding,axis=1)
        return embedding 
开发者ID:944284742,项目名称:1.FaceRecognition,代码行数:15,代码来源:faces_classer.py

示例14: predict

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def predict(self, img):
        img = nd.array(img)
        img = nd.transpose(img, axes=(2, 0, 1)).astype('float32')
        img = nd.expand_dims(img, axis=0)
        # print(img.shape)
        db = mx.io.DataBatch(data=(img,))

        self.model.forward(db, is_train=False)
        net_out = self.model.get_outputs()
        embedding = net_out[0].asnumpy()
        embedding = sklearn.preprocessing.normalize(embedding)
        return embedding 
开发者ID:944284742,项目名称:1.FaceRecognition,代码行数:14,代码来源:delete_same_face.py

示例15: predict

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import transpose [as 别名]
def predict(self,img):
        img = nd.array(img)
        img = nd.transpose(img, axes=(2, 0, 1)).astype('float32')
        img = nd.expand_dims(img, axis=0)
        #print(img.shape)
        db = mx.io.DataBatch(data=(img,))

        self.model.forward(db, is_train=False)
        net_out = self.model.get_outputs()
        embedding = net_out[0].asnumpy()
        embedding = sklearn.preprocessing.normalize(embedding)
        return embedding 
开发者ID:944284742,项目名称:1.FaceRecognition,代码行数:14,代码来源:dataset_clean.py


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