本文整理汇总了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
示例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
示例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))
示例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)
示例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)
示例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))
示例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
#
示例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
示例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