當前位置: 首頁>>代碼示例>>Python>>正文


Python tensorflow.invert_permutation方法代碼示例

本文整理匯總了Python中tensorflow.invert_permutation方法的典型用法代碼示例。如果您正苦於以下問題:Python tensorflow.invert_permutation方法的具體用法?Python tensorflow.invert_permutation怎麽用?Python tensorflow.invert_permutation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.invert_permutation方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: multilevel_roi_align

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def multilevel_roi_align(self, features, rcnn_boxes, output_shape):
    config = self.config
    assert len(features) == 4
    # Reassign rcnn_boxes to levels # based on box area size
    level_ids, level_boxes = self.fpn_map_rois_to_levels(rcnn_boxes)
    all_rois = []

    # Crop patches from corresponding levels
    for i, boxes, featuremap in zip(itertools.count(), level_boxes, features):
      with tf.name_scope("roi_level%s" % (i + 2)):
        boxes_on_featuremap = boxes * (1.0 / config.anchor_strides[i])
        all_rois.append(
            roi_align(featuremap, boxes_on_featuremap, output_shape))

    # this can fail if using TF<=1.8 with MKL build
    all_rois = tf.concat(all_rois, axis=0)  # NCHW
    # Unshuffle to the original order, to match the original samples
    level_id_perm = tf.concat(level_ids, axis=0)  # A permutation of 1~N
    level_id_invert_perm = tf.invert_permutation(level_id_perm)
    all_rois = tf.gather(all_rois, level_id_invert_perm)
    return all_rois 
開發者ID:JunweiLiang,項目名稱:Object_Detection_Tracking,代碼行數:23,代碼來源:models.py

示例2: calculate_allocation_weighting

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def calculate_allocation_weighting(self, usage_vector):
        """

        :param: usage vector: tensor of shape [batch_size, memory_size]
        :return: allocation tensor of shape [batch_size, memory_size]
        """
        usage_vector = Memory.epsilon + (1 - Memory.epsilon) * usage_vector

        # We're sorting the "-self.usage_vector" because top_k returns highest values and we need the lowest
        highest_usage, inverse_indices = tf.nn.top_k(-usage_vector, k=self.memory_size)
        lowest_usage = -highest_usage

        allocation_scrambled = (1 - lowest_usage) * tf.cumprod(lowest_usage, axis=1, exclusive=True)

        # allocation is not in the correct order. alloation[i] contains the sorted[i] value
        # reversing the already inversed indices for each batch
        indices = tf.stack([tf.invert_permutation(batch_indices) for batch_indices in tf.unstack(inverse_indices)])
        allocation = tf.stack([tf.gather(mem, ind)
                               for mem, ind in
                               zip(tf.unstack(allocation_scrambled), tf.unstack(indices))])

        return allocation 
開發者ID:bgavran,項目名稱:DNC,代碼行數:24,代碼來源:memory.py

示例3: batch_invert_permutation

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def batch_invert_permutation(permutations):
  """Returns batched `tf.invert_permutation` for every row in `permutations`."""
  with tf.name_scope('batch_invert_permutation', values=[permutations]):
    perm = tf.cast(permutations, tf.float32)
    dim = int(perm.get_shape()[-1])
    size = tf.cast(tf.shape(perm)[0], tf.float32)
    delta = tf.cast(tf.shape(perm)[-1], tf.float32)
    rg = tf.range(0, size * delta, delta, dtype=tf.float32)
    rg = tf.expand_dims(rg, 1)
    rg = tf.tile(rg, [1, dim])
    perm = tf.add(perm, rg)
    flat = tf.reshape(perm, [-1])
    perm = tf.invert_permutation(tf.cast(flat, tf.int32))
    perm = tf.reshape(perm, [-1, dim])
    return tf.subtract(perm, tf.cast(rg, tf.int32)) 
開發者ID:deepmind,項目名稱:dnc,代碼行數:17,代碼來源:util.py

示例4: _invert_permutation

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def _invert_permutation(input, row_count):
    '''wrapper for matrix'''
    rows = []
    for i in range(row_count):
        row = input[i,:]
        rows.append(tf.invert_permutation(row))
    return tf.cast(tf.stack(rows, axis=0), tf.float32) 
開發者ID:rec-agent,項目名稱:rec-rl,代碼行數:9,代碼來源:rec_input_fn_local.py

示例5: _invert_permutation

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def _invert_permutation(tensor):
    '''wrapper for matrix'''
    return tf.cast(tf.map_fn(tf.invert_permutation, tensor), tf.float32) 
開發者ID:rec-agent,項目名稱:rec-rl,代碼行數:5,代碼來源:rec_env.py

示例6: inverse_selection

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def inverse_selection(y, presence, batch_size=1, name='inverse_selection'):
    with tf.variable_scope(name):
        idx = tf.reshape(tf.range(tf.size(y)), tf.shape(y))
        idx = tf.reshape(select_present(idx, presence, batch_size), (-1,))
        idx = tf.invert_permutation(idx)

        x = tf.gather(tf.reshape(y, (-1,)), idx)
    return tf.reshape(x, tf.shape(y)) 
開發者ID:akosiorek,項目名稱:hart,代碼行數:10,代碼來源:tensor_ops.py

示例7: test_InvertPermutation

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def test_InvertPermutation(self):
        t = tf.invert_permutation(np.random.permutation(10))
        self.check(t)


    #
    # control flow ops
    # 
開發者ID:riga,項目名稱:tfdeploy,代碼行數:10,代碼來源:ops.py

示例8: multilevel_roi_align

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def multilevel_roi_align(fpn_feats, boxes, level_indexes, output_shape,
                         eff_config):
  """
    Given [R, 4] boxes and [R] level_indexes indicating the FPN level
    # boxes are x1, y1, x2, y2
  """
  # gather boxes for each feature level
  all_rois = []
  level_ids = []
  # for debuging
  #boxes_on_fp = []
  #1920 -> [160, 80, 40, 20, 10]/{3, 4, 5, 6, 7}
  for level in range(eff_config.min_level, eff_config.max_level + 1):
    this_level_boxes_idxs = tf.where(tf.equal(level_indexes, level))
    # [K, 1] -> [K]
    this_level_boxes_idxs = tf.reshape(this_level_boxes_idxs, [-1])
    level_ids.append(this_level_boxes_idxs)
    this_level_boxes = tf.gather(boxes, this_level_boxes_idxs)
    boxes_on_featuremap = this_level_boxes * (1.0 / (2. ** level))
    featuremap = fpn_feats[level]  # [1, H, W, C]
    # [K, output_shape, output_shape, C]
    box_feats = roi_align(featuremap, boxes_on_featuremap, output_shape)
    box_feats = tf.reduce_mean(box_feats, axis=[1, 2])  #  [K, C]
    all_rois.append(box_feats)

    # for debugging
    #boxes_on_fp.append(boxes_on_featuremap)

  all_rois = tf.concat(all_rois, axis=0)
  # Unshuffle to the original order, to match the original samples
  level_id_perm = tf.concat(level_ids, axis=0)  # A permutation of 1~N
  level_id_invert_perm = tf.invert_permutation(level_id_perm)
  all_rois = tf.gather(all_rois, level_id_invert_perm)

  #boxes_on_fp = tf.concat(boxes_on_fp, axis=0)
  #boxes_on_fp = tf.gather(boxes_on_fp, level_id_invert_perm)
  return all_rois#, boxes_on_fp 
開發者ID:JunweiLiang,項目名稱:Object_Detection_Tracking,代碼行數:39,代碼來源:efficientdet_wrapper.py

示例9: multilevel_roi_align

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import invert_permutation [as 別名]
def multilevel_roi_align(features, rcnn_boxes, resolution):
    """
    Args:
        features ([tf.Tensor]): 4 FPN feature level 2-5
        rcnn_boxes (tf.Tensor): nx4 boxes
        resolution (int): output spatial resolution
    Returns:
        NxC x res x res
    """
    assert len(features) == 4, features
    # Reassign rcnn_boxes to levels
    level_ids, level_boxes = fpn_map_rois_to_levels(rcnn_boxes)
    all_rois = []

    # Crop patches from corresponding levels
    for i, boxes, featuremap in zip(itertools.count(), level_boxes, features):
        with tf.name_scope('roi_level{}'.format(i + 2)):
            boxes_on_featuremap = boxes * (1.0 / cfg.FPN.ANCHOR_STRIDES[i])
            all_rois.append(roi_align(featuremap, boxes_on_featuremap, resolution))

    # this can fail if using TF<=1.8 with MKL build
    all_rois = tf.concat(all_rois, axis=0)  # NCHW
    # Unshuffle to the original order, to match the original samples
    level_id_perm = tf.concat(level_ids, axis=0)  # A permutation of 1~N
    level_id_invert_perm = tf.invert_permutation(level_id_perm)
    all_rois = tf.gather(all_rois, level_id_invert_perm, name="output")
    return all_rois 
開發者ID:tensorpack,項目名稱:tensorpack,代碼行數:29,代碼來源:model_fpn.py


注:本文中的tensorflow.invert_permutation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。