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


Python tensorflow.random_shuffle方法代码示例

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


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

示例1: scheduled_sample

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def scheduled_sample(ground_truth_x, generated_x, batch_size, num_ground_truth):
  """Sample batch with specified mix of ground truth and generated data points.

  Args:
    ground_truth_x: tensor of ground-truth data points.
    generated_x: tensor of generated data points.
    batch_size: batch size
    num_ground_truth: number of ground-truth examples to include in batch.
  Returns:
    New batch with num_ground_truth sampled from ground_truth_x and the rest
    from generated_x.
  """
  idx = tf.random_shuffle(tf.range(int(batch_size)))
  ground_truth_idx = tf.gather(idx, tf.range(num_ground_truth))
  generated_idx = tf.gather(idx, tf.range(num_ground_truth, int(batch_size)))

  ground_truth_examps = tf.gather(ground_truth_x, ground_truth_idx)
  generated_examps = tf.gather(generated_x, generated_idx)
  return tf.dynamic_stitch([ground_truth_idx, generated_idx],
                           [ground_truth_examps, generated_examps]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:22,代码来源:prediction_model.py

示例2: scheduled_sample

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def scheduled_sample(self,
                       ground_truth_x,
                       generated_x,
                       batch_size,
                       num_ground_truth):
    """Sample batch with specified mix of groundtruth and generated data points.

    Args:
      ground_truth_x: tensor of ground-truth data points.
      generated_x: tensor of generated data points.
      batch_size: batch size
      num_ground_truth: number of ground-truth examples to include in batch.
    Returns:
      New batch with num_ground_truth sampled from ground_truth_x and the rest
      from generated_x.
    """
    idx = tf.random_shuffle(tf.range(batch_size))
    ground_truth_idx = tf.gather(idx, tf.range(num_ground_truth))
    generated_idx = tf.gather(idx, tf.range(num_ground_truth, batch_size))

    ground_truth_examps = tf.gather(ground_truth_x, ground_truth_idx)
    generated_examps = tf.gather(generated_x, generated_idx)
    return tf.dynamic_stitch([ground_truth_idx, generated_idx],
                             [ground_truth_examps, generated_examps]) 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:26,代码来源:next_frame.py

示例3: aspect_ratio_jittering

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def aspect_ratio_jittering(img_tensor, gtboxes_and_label, aspect_ratio=(0.8, 1.5)):
    ratio_list = tf.range(aspect_ratio[0], aspect_ratio[1], delta=0.025)
    ratio = tf.random_shuffle(ratio_list)[0]

    img_h, img_w = tf.shape(img_tensor)[0], tf.shape(img_tensor)[1]
    areas = img_h * img_w
    areas = tf.cast(areas, tf.float32)
    short_side = tf.sqrt(areas / ratio)
    long_side = short_side * ratio
    short_side = tf.cast(short_side, tf.int32)
    long_side = tf.cast(long_side, tf.int32)

    image, gtbox, new_h, new_w = tf.cond(tf.less(img_w, img_h),
                                         true_fn=lambda: tf_resize_image(img_tensor, gtboxes_and_label, short_side,
                                                                         long_side),
                                         false_fn=lambda: tf_resize_image(img_tensor, gtboxes_and_label, long_side,
                                                                          short_side))

    return image, gtbox, new_h, new_w 
开发者ID:Thinklab-SJTU,项目名称:R3Det_Tensorflow,代码行数:21,代码来源:image_preprocess_multi_gpu.py

示例4: rotate_img

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def rotate_img(img_tensor, gtboxes_and_label):

    # thetas = tf.constant([-30, -60, -90, 30, 60, 90])
    thetas = tf.range(-90, 90+16, delta=15)
    # -90, -75, -60, -45, -30, -15,   0,  15,  30,  45,  60,  75,  90

    theta = tf.random_shuffle(thetas)[0]

    img_tensor, gtboxes_and_label = tf.py_func(rotate_img_np,
                                               inp=[img_tensor, gtboxes_and_label, theta],
                                               Tout=[tf.float32, tf.int32])

    h, w, c = tf.shape(img_tensor)[0], tf.shape(img_tensor)[1], tf.shape(img_tensor)[2]
    img_tensor = tf.reshape(img_tensor, [h, w, c])
    gtboxes_and_label = tf.reshape(gtboxes_and_label, [-1, 9])

    return img_tensor, gtboxes_and_label 
开发者ID:Thinklab-SJTU,项目名称:R3Det_Tensorflow,代码行数:19,代码来源:image_preprocess_multi_gpu.py

示例5: read_from_disk

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def read_from_disk(self,queue):
        index_t=queue[0]#tf.random_shuffle(self.input_list)[0]
        index_min=tf.reshape(tf.where(tf.less_equal(self.node,index_t)),[-1])
        node_min=self.node[index_min[-1]]
        node_max=self.node[index_min[-1]+1]
        interval_list=list(range(30,100))
        interval=tf.random_shuffle(interval_list)[0]
        index_d=[tf.cond(tf.greater(index_t-interval,node_min),lambda:index_t-interval,lambda:index_t+interval),tf.cond(tf.less(index_t+interval,node_max),lambda:index_t+interval,lambda:index_t-interval)]
        index_d=tf.random_shuffle(index_d)
        index_d=index_d[0]

        constant_t=tf.read_file(self.img_list[index_t])
        template=tf.image.decode_jpeg(constant_t, channels=3)
        template=template[:,:,::-1]
        constant_d=tf.read_file(self.img_list[index_d])
        detection=tf.image.decode_jpeg(constant_d, channels=3)
        detection=detection[:,:,::-1]

        template_label=self.label_list[index_t]
        detection_label=self.label_list[index_d]

        template_p,template_label_p,_,_=self.crop_resize(template,template_label,1)
        detection_p,detection_label_p,offset,ratio=self.crop_resize(detection,detection_label,2)

        return template_p,template_label_p,detection_p,detection_label_p,offset,ratio,detection,detection_label,index_t,index_d 
开发者ID:makalo,项目名称:Siamese-RPN-tensorflow,代码行数:27,代码来源:image_reader_cuda.py

示例6: _random_tensor_gather

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def _random_tensor_gather(array, num_ind, name=None):
  """Samples random indices of an array (along the first dimension).

  Args:
    array: Tensor of shape `[batch_size, ...]`.
    num_ind: int. Number of indices to sample.
    name: `string`. (Default: None)

  Returns:
    A tensor of shape `[num_ind, ...]`.
  """
  with tf.name_scope(name, "random_gather", [array]):
    array = tf.convert_to_tensor(array)
    total_size = array.shape.as_list()[0]
    if total_size is None:
      total_size = utils.get_shape(array)[0]
    indices = tf.random_shuffle(tf.range(0, total_size))[:num_ind]
    return tf.gather(array, indices, axis=0) 
开发者ID:tensorflow,项目名称:kfac,代码行数:20,代码来源:fisher_factors.py

示例7: scheduled_sample

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def scheduled_sample(ground_truth_x, generated_x, batch_size, num_ground_truth):
    """Sample batch with specified mix of ground truth and generated data_files points.

    Args:
      ground_truth_x: tensor of ground-truth data_files points.
      generated_x: tensor of generated data_files points.
      batch_size: batch size
      num_ground_truth: number of ground-truth examples to include in batch.
    Returns:
      New batch with num_ground_truth sampled from ground_truth_x and the rest
      from generated_x.
    """
    idx = tf.random_shuffle(tf.range(int(batch_size)))
    ground_truth_idx = tf.gather(idx, tf.range(num_ground_truth))
    generated_idx = tf.gather(idx, tf.range(num_ground_truth, int(batch_size)))

    ground_truth_examps = tf.gather(ground_truth_x, ground_truth_idx)
    generated_examps = tf.gather(generated_x, generated_idx)
    return tf.dynamic_stitch([ground_truth_idx, generated_idx],
                             [ground_truth_examps, generated_examps]) 
开发者ID:alexlee-gk,项目名称:video_prediction,代码行数:22,代码来源:sna_model.py

示例8: scheduled_sample

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def scheduled_sample(ground_truth_x, generated_x, batch_size, num_ground_truth):
    """Sample batch with specified mix of ground truth and generated data points.

    Args:
        ground_truth_x: tensor of ground-truth data points.
        generated_x: tensor of generated data points.
        batch_size: batch size
        num_ground_truth: number of ground-truth examples to include in batch.
    Returns:
        New batch with num_ground_truth sampled from ground_truth_x and the rest
        from generated_x.
    """
    idx = tf.random_shuffle(tf.range(int(batch_size)))
    ground_truth_idx = tf.gather(idx, tf.range(num_ground_truth))
    generated_idx = tf.gather(idx, tf.range(num_ground_truth, int(batch_size)))

    ground_truth_examps = tf.gather(ground_truth_x, ground_truth_idx)
    generated_examps = tf.gather(generated_x, generated_idx)
    return tf.dynamic_stitch([ground_truth_idx, generated_idx],
                             [ground_truth_examps, generated_examps]) 
开发者ID:alexlee-gk,项目名称:video_prediction,代码行数:22,代码来源:sv2p_model.py

示例9: sample_k_fids_for_pid

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def sample_k_fids_for_pid(pid, all_fids, all_pids, batch_k):
    """ Given a PID, select K FIDs of that specific PID. """
    possible_fids = tf.boolean_mask(all_fids, tf.equal(all_pids, pid))

    # The following simply uses a subset of K of the possible FIDs
    # if more than, or exactly K are available. Otherwise, we first
    # create a padded list of indices which contain a multiple of the
    # original FID count such that all of them will be sampled equally likely.
    count = tf.shape(possible_fids)[0]
    padded_count = tf.cast(tf.ceil(batch_k / tf.cast(count, tf.float32)), tf.int32) * count
    full_range = tf.mod(tf.range(padded_count), count)

    # Sampling is always performed by shuffling and taking the first k.
    shuffled = tf.random_shuffle(full_range)
    selected_fids = tf.gather(possible_fids, shuffled[:batch_k])

    return selected_fids, tf.fill([batch_k], pid) 
开发者ID:VisualComputingInstitute,项目名称:triplet-reid,代码行数:19,代码来源:train.py

示例10: _generate_rand

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def _generate_rand(min_factor, max_factor, step_size):
    """Gets a random value.
         Args:
            min_factor: Minimum value.
            max_factor: Maximum value.
            step_size: The step size from minimum to maximum value.
         Returns:
            A random value selected between minimum and maximum value.
         Raises:
            ValueError: min_factor has unexpected value.
    """
    if min_factor < 0 or min_factor > max_factor:
        raise ValueError("Unexpected value of min_factor.")
    if min_factor == max_factor:
        return tf.to_float(min_factor)
        # When step_size = 0, we sample the value uniformly from [min, max).
    if step_size == 0:
        return tf.random_uniform([1],
                                 minval=min_factor,
                                 maxval=max_factor)
        # When step_size != 0, we randomly select one discrete value from [min, max].
    num_steps = int((max_factor - min_factor) / step_size + 1)
    scale_factors = tf.lin_space(min_factor, max_factor, num_steps)
    shuffled_scale_factors = tf.random_shuffle(scale_factors)
    return shuffled_scale_factors[0] 
开发者ID:hyperconnect,项目名称:MMNet,代码行数:27,代码来源:augmentation_factory.py

示例11: sample_k_fids_for_pid

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def sample_k_fids_for_pid(pid, all_fids, all_pids, batch_k):
    """ Given a PID, select K FIDs of that specific PID. """
    possible_fids = tf.boolean_mask(all_fids, tf.equal(all_pids, pid))

    # The following simply uses a subset of K of the possible FIDs
    # if more than, or exactly K are available. Otherwise, we first
    # create a padded list of indices which contain a multiple of the
    # original FID count such that all of them will be sampled equally likely.
    count = tf.shape(possible_fids)[0]
    padded_count = tf.cast(tf.ceil(batch_k / count), tf.int32) * count
    full_range = tf.mod(tf.range(padded_count), count)

    # Sampling is always performed by shuffling and taking the first k.
    shuffled = tf.random_shuffle(full_range)
    selected_fids = tf.gather(possible_fids, shuffled[:batch_k])

    return selected_fids, tf.fill([batch_k], pid) 
开发者ID:knwng,项目名称:vehicle-triplet-reid,代码行数:19,代码来源:train.py

示例12: parse_sentence

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def parse_sentence(serialized):
  """Parses a tensorflow.SequenceExample into an caption.

  Args:
    serialized: A scalar string Tensor; a single serialized SequenceExample.

  Returns:
    key: The keywords in a sentence.
    num_key: The number of keywords.
    sentence: A description.
    sentence_length: The length of the description.
  """
  context, sequence = tf.parse_single_sequence_example(
    serialized,
    context_features={},
    sequence_features={
      'key': tf.FixedLenSequenceFeature([], dtype=tf.int64),
      'sentence': tf.FixedLenSequenceFeature([], dtype=tf.int64),
    })
  key = tf.to_int32(sequence['key'])
  key = tf.random_shuffle(key)
  sentence = tf.to_int32(sequence['sentence'])
  return key, tf.shape(key)[0], sentence, tf.shape(sentence)[0] 
开发者ID:fengyang0317,项目名称:unsupervised_captioning,代码行数:25,代码来源:obj2sen.py

示例13: subsample_indicator

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def subsample_indicator(indicator, num_samples):
    """Subsample indicator vector.

    Given a boolean indicator vector with M elements set to `True`, the function
    assigns all but `num_samples` of these previously `True` elements to
    `False`. If `num_samples` is greater than M, the original indicator vector
    is returned.

    Args:
      indicator: a 1-dimensional boolean tensor indicating which elements
        are allowed to be sampled and which are not.
      num_samples: int32 scalar tensor

    Returns:
      a boolean tensor with the same shape as input (indicator) tensor
    """
    indices = tf.where(indicator)
    indices = tf.random_shuffle(indices)
    indices = tf.reshape(indices, [-1])

    num_samples = tf.minimum(tf.size(indices), num_samples)
    selected_indices = tf.slice(indices, [0], tf.reshape(num_samples, [1]))

    selected_indicator = ops.indices_to_dense_vector(selected_indices,
                                                     tf.shape(indicator)[0])

    return tf.equal(selected_indicator, 1) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:29,代码来源:minibatch_sampler.py

示例14: _get_randomized_indices

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def _get_randomized_indices(self):
    """Generates randomized indices into a sequence of a specific length."""
    indices = tf.range(0, self._dataset_info.sequence_size)
    indices = tf.random_shuffle(indices)
    indices = tf.slice(indices, begin=[0], size=[self._example_size])
    return indices 
开发者ID:deepmind,项目名称:gqn-datasets,代码行数:8,代码来源:data_reader.py

示例15: HoMM4

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_shuffle [as 别名]
def HoMM4(xs,xt):
	ind=tf.range(tf.cast(xs.shape[1],tf.int32))
	ind=tf.random_shuffle(ind)
	xs=tf.transpose(xs,[1,0])
	xs=tf.gather(xs,ind)
	xs = tf.transpose(xs, [1, 0])
	xt = tf.transpose(xt, [1, 0])
	xt = tf.gather(xt, ind)
	xt = tf.transpose(xt, [1, 0])
	return HoMM4_loss(xs[:,:30],xt[:,:30])+HoMM4_loss(xs[:,30:60],xt[:,30:60])+HoMM4_loss(xs[:,60:90],xt[:,60:90]) 
开发者ID:yyht,项目名称:BERT,代码行数:12,代码来源:homm_utils.py


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