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


Python v1.argmin方法代碼示例

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


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

示例1: GetDiscreteActionLoss

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import argmin [as 別名]
def GetDiscreteActionLoss(logits, action_labels, bin_centers, num_bins):
  """Convert labels to one-hot, compute cross-entropy loss, and return loss.

  Args:
    logits: Tensor corresponding to the predicted action logits, with size
      [batch_size, timesteps, action_dim*num_bins]
    action_labels: Tensor corresponding to the real valued action labels, with
      size [batch_size, 1, timesteps, action_dim]
    bin_centers: numpy array of size [num_bins, action_dim] corresponding to
      the centers of each bin for each dimension.
    num_bins: number of discrete bins.
  Returns:
    Scalar tensor, cross entropy loss between the predicted actions and labels.
  """
  action_labels = tf.expand_dims(action_labels, -2)
  bin_centers = tf.constant(bin_centers, dtype=tf.float32)
  while len(bin_centers.shape) < len(action_labels.shape):
    bin_centers = tf.expand_dims(bin_centers, 0)
  discrete_labels = tf.argmin((action_labels - bin_centers)**2, -2)
  onehot_labels = tf.one_hot(discrete_labels, num_bins)
  onehot_labels = tf.reshape(onehot_labels, (-1, num_bins))
  logits = tf.reshape(logits, (-1, num_bins))
  loss = tf.nn.softmax_cross_entropy_with_logits_v2(onehot_labels, logits)
  loss = tf.reduce_mean(loss)
  return loss 
開發者ID:google-research,項目名稱:tensor2robot,代碼行數:27,代碼來源:discrete.py

示例2: _get_least_likely_class

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import argmin [as 別名]
def _get_least_likely_class(label, num_classes, logits):
  target_label = tf.argmin(logits, axis=1, output_type=tf.int64)
  # In the off-chance that the least likely class is the true class, the target
  # class is changed to the be the next index.
  return tf.mod(target_label + tf.cast(
      tf.equal(target_label, tf.cast(label, tf.int64)), tf.int64), num_classes) 
開發者ID:deepmind,項目名稱:interval-bound-propagation,代碼行數:8,代碼來源:utils.py

示例3: _find_interval_containing_new_value

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import argmin [as 別名]
def _find_interval_containing_new_value(x, new_value):
  """Find the index of x (ascending-ordered) after which new_value occurs."""
  new_value_shape = shape_utils.combined_static_and_dynamic_shape(new_value)[0]
  x_shape = shape_utils.combined_static_and_dynamic_shape(x)[0]
  compare = tf.cast(tf.reshape(new_value, shape=(new_value_shape, 1)) >=
                    tf.reshape(x, shape=(1, x_shape)),
                    dtype=tf.int32)
  diff = compare[:, 1:] - compare[:, :-1]
  interval_idx = tf.argmin(diff, axis=1)
  return interval_idx 
開發者ID:tensorflow,項目名稱:models,代碼行數:12,代碼來源:calibration_builder.py

示例4: test_forward_argminmax

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import argmin [as 別名]
def test_forward_argminmax():
    for axis in [None, 0, 1, 2]:
        data = np.random.uniform(size=(8, 4, 9)).astype('float32')
        _test_argx(tf.argmax, data=data, axis=axis)
        _test_argx(tf.argmin, data=data, axis=axis)


#######################################################################
# Variable
# -------- 
開發者ID:apache,項目名稱:incubator-tvm,代碼行數:12,代碼來源:test_forward.py

示例5: parse_learning_rate

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import argmin [as 別名]
def parse_learning_rate(step, learning_rate):
  """Returns the learning rate as a tensor."""
  if isinstance(learning_rate, float):
    return learning_rate
  # Learning rate schedule of the form:
  # initial_learning_rate[,learning@steps]*. E.g., "1e-3" or
  # "1e-3,1e-4@15000,1e-5@25000". We use eval to allow learning specified as
  # fractions (e.g., 2/255).
  tokens = learning_rate.split(',')
  first_lr = float(eval(tokens[0]))  # pylint: disable=eval-used
  if len(tokens) == 1:
    return tf.constant(first_lr, dtype=tf.float32)
  # Parse steps.
  init_values = [first_lr]
  final_values = []
  init_step = [0]
  final_step = []
  for t in tokens[1:]:
    if '@' in t:
      lr, boundary = t.split('@', 1)
      is_linear = False
    elif 'S' in t:  # Syntactic sugar to indicate a step.
      lr, boundary = t.split('S', 1)
      is_linear = False
    elif 'L' in t:
      lr, boundary = t.split('L', 1)
      is_linear = True
    else:
      raise ValueError('Unknown specification.')
    lr = float(eval(lr))  # pylint: disable=eval-used
    init_values.append(lr)
    if is_linear:
      final_values.append(lr)
    else:
      final_values.append(init_values[-2])
    boundary = int(boundary)
    init_step.append(boundary)
    final_step.append(boundary)
  large_step = max(final_step) + 1
  final_step.append(large_step)
  final_values.append(lr)

  # Find current index.
  boundaries = list(final_step) + [large_step + 2]
  boundaries = tf.convert_to_tensor(boundaries, dtype=tf.int64)
  b = boundaries - tf.minimum(step + 1, large_step + 1)
  large_step = tf.constant(
      large_step, shape=boundaries.shape, dtype=step.dtype)
  b = tf.where(b < 0, large_step, b)
  idx = tf.minimum(tf.argmin(b), len(init_values) - 1)

  init_step = tf.convert_to_tensor(init_step, dtype=tf.float32)
  final_step = tf.convert_to_tensor(final_step, dtype=tf.float32)
  init_values = tf.convert_to_tensor(init_values, dtype=tf.float32)
  final_values = tf.convert_to_tensor(final_values, dtype=tf.float32)
  x1 = tf.gather(init_step, idx)
  x2 = tf.gather(final_step, idx)
  y1 = tf.gather(init_values, idx)
  y2 = tf.gather(final_values, idx)
  return (tf.cast(step, tf.float32) - x1) / (x2 - x1) * (y2 - y1) + y1 
開發者ID:deepmind,項目名稱:interval-bound-propagation,代碼行數:62,代碼來源:utils.py

示例6: fill_in_the_blank_sized

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import argmin [as 別名]
def fill_in_the_blank_sized(
    dataset,
    size_bins=(1, 2, 4, 8, 16, 32, 64, 128, 256, 512),
    text_key='text',
    label='fill: '):
  """Fill in the blank preprocessor that labels blank with a binned size.

  The actual blank size is sampled uniformly from the inclusive range of the min
  and max bin. The blank is then filled in with the closest bin size to the
  actual blank size.

  Args:
    dataset: a tf.data.Dataset, the dataset to preprocess.
    size_bins: a list, a list of blank sizes to select from when labelling the
      blank.
    text_key: a string, the key for the text feature to preprocess in the
      dataset examples.
    label: a string, the label to prepend to the inputs.

  Returns:
    a tf.data.Dataset
  """
  bins = sorted(size_bins)

  def my_fn(x):
    """Apply transformation."""
    words = x['words']
    n_words = tf.size(words)

    blank_size = tf.random.uniform(
        [], minval=bins[0], maxval=tf.math.minimum(n_words, bins[-1]),
        dtype=tf.dtypes.int32)
    bin_delta = tf.math.abs(bins - blank_size)
    bin_ = tf.gather(bins, tf.argmin(bin_delta))
    blank_start = tf.random.uniform(
        [], minval=0, maxval=tf.math.maximum(0, n_words-blank_size) + 1,
        dtype=tf.dtypes.int32)

    pre_blank = tf.strings.reduce_join(words[0:blank_start], separator=' ')
    post_blank = tf.strings.reduce_join(
        words[blank_start+blank_size:], separator=' ')
    blank = tf.strings.format('_{}_', bin_)
    # We strip to handle cases where blank is at beginning or end.
    input_ = tf.strings.strip(
        tf.strings.join([pre_blank, blank, post_blank], ' '))
    input_ = tf.strings.join([label, input_])
    target = tf.strings.reduce_join(
        words[blank_start:blank_start+blank_size], separator=' ')
    return {
        'inputs': tf.strings.strip(input_),
        'targets': tf.strings.strip(target)}
  dataset = _split_text_to_words(dataset, text_key, min_num_words=2)
  # Filter out examples with fewer words than the minimum.
  dataset = dataset.filter(lambda x: tf.size(x['words']) >= bins[0])
  dataset = dataset.map(my_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE)
  return dataset 
開發者ID:google-research,項目名稱:text-to-text-transfer-transformer,代碼行數:58,代碼來源:preprocessors.py


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