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


Python math_ops.less_equal函数代码示例

本文整理汇总了Python中tensorflow.python.ops.math_ops.less_equal函数的典型用法代码示例。如果您正苦于以下问题:Python less_equal函数的具体用法?Python less_equal怎么用?Python less_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: maybe_update_masks

 def maybe_update_masks():
   with ops.name_scope(self._spec.name):
     is_step_within_pruning_range = math_ops.logical_and(
         math_ops.greater_equal(self._global_step,
                                self._spec.begin_pruning_step),
         # If end_pruning_step is negative, keep pruning forever!
         math_ops.logical_or(
             math_ops.less_equal(self._global_step,
                                 self._spec.end_pruning_step),
             math_ops.less(self._spec.end_pruning_step, 0)))
     is_pruning_step = math_ops.less_equal(
         math_ops.add(self._last_update_step, self._spec.pruning_frequency),
         self._global_step)
     return math_ops.logical_and(is_step_within_pruning_range,
                                 is_pruning_step)
开发者ID:SylChan,项目名称:tensorflow,代码行数:15,代码来源:pruning.py

示例2: _filter_input

def _filter_input(input_tensor, vocab_freq_table, vocab_min_count,
                  vocab_subsampling, corpus_size, seed):
  """Filters input tensor based on vocab freq, threshold, and subsampling."""
  if vocab_freq_table is None:
    return input_tensor

  if not isinstance(vocab_freq_table, lookup.InitializableLookupTableBase):
    raise ValueError(
        "vocab_freq_table must be a subclass of "
        "InitializableLookupTableBase (such as HashTable) instead of type "
        "{}.".format(type(vocab_freq_table)))

  with ops.name_scope(
      "filter_vocab", values=[vocab_freq_table, input_tensor, vocab_min_count]):
    freq = vocab_freq_table.lookup(input_tensor)
    # Filters out elements in input_tensor that are not found in
    # vocab_freq_table (table returns a default value of -1 specified above when
    # an element is not found).
    mask = math_ops.not_equal(freq, vocab_freq_table.default_value)

    # Filters out elements whose vocab frequencies are less than the threshold.
    if vocab_min_count is not None:
      cast_threshold = math_ops.cast(vocab_min_count, freq.dtype)
      mask = math_ops.logical_and(mask,
                                  math_ops.greater_equal(freq, cast_threshold))

    input_tensor = array_ops.boolean_mask(input_tensor, mask)
    freq = array_ops.boolean_mask(freq, mask)

  if not vocab_subsampling:
    return input_tensor

  if vocab_subsampling < 0 or vocab_subsampling > 1:
    raise ValueError(
        "Invalid vocab_subsampling={} - it should be within range [0, 1].".
        format(vocab_subsampling))

  # Subsamples the input tokens based on vocabulary frequency and
  # vocab_subsampling threshold (ie randomly discard commonly appearing
  # tokens).
  with ops.name_scope(
      "subsample_vocab", values=[input_tensor, freq, vocab_subsampling]):
    corpus_size = math_ops.cast(corpus_size, dtypes.float64)
    freq = math_ops.cast(freq, dtypes.float64)
    vocab_subsampling = math_ops.cast(vocab_subsampling, dtypes.float64)

    # From tensorflow_models/tutorials/embedding/word2vec_kernels.cc, which is
    # suppose to correlate with Eq. 5 in http://arxiv.org/abs/1310.4546.
    keep_prob = ((math_ops.sqrt(freq /
                                (vocab_subsampling * corpus_size)) + 1.0) *
                 (vocab_subsampling * corpus_size / freq))
    random_prob = random_ops.random_uniform(
        array_ops.shape(freq),
        minval=0,
        maxval=1,
        dtype=dtypes.float64,
        seed=seed)

    mask = math_ops.less_equal(random_prob, keep_prob)
    return array_ops.boolean_mask(input_tensor, mask)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:60,代码来源:skip_gram_ops.py

示例3: _single_seq_fn

 def _single_seq_fn():
   log_norm = math_ops.reduce_logsumexp(first_input, [1])
   # Mask `log_norm` of the sequences with length <= zero.
   log_norm = array_ops.where(math_ops.less_equal(sequence_lengths, 0),
                              array_ops.zeros_like(log_norm),
                              log_norm)
   return log_norm
开发者ID:Jordan1237,项目名称:tensorflow,代码行数:7,代码来源:crf.py

示例4: assert_less_equal

def assert_less_equal(x, y, data=None, summarize=None, name=None):
  """Assert the condition `x <= y` holds element-wise.

  This condition holds if for every pair of (possibly broadcast) elements
  `x[i]`, `y[i]`, we have `x[i] <= y[i]`.
  If both `x` and `y` are empty, this is trivially satisfied.

  Args:
    x:  Numeric `Tensor`.
    y:  Numeric `Tensor`, same dtype as and broadcastable to `x`.
    data:  The tensors to print out if the condition is False.  Defaults to
      error message and first few entries of `x`, `y`.
    summarize: Print this many entries of each tensor.
    name: A name for this operation (optional).  Defaults to "assert_less_equal"

  Returns:
    Op that raises `InvalidArgumentError` if `x <= y` is False.
  """
  with ops.op_scope([x, y, data], name, 'assert_less_equal'):
    x = ops.convert_to_tensor(x, name='x')
    y = ops.convert_to_tensor(y, name='y')
    if data is None:
      data = [
          'Condition x <= y did not hold element-wise: x = ', x.name, x, 'y = ',
          y.name, y
      ]
    condition = math_ops.reduce_all(math_ops.less_equal(x, y))
    return logging_ops.Assert(condition, data, summarize=summarize)
开发者ID:2er0,项目名称:tensorflow,代码行数:28,代码来源:check_ops.py

示例5: _hinge_loss

def _hinge_loss(logits, target):
  check_shape_op = control_flow_ops.Assert(
      math_ops.less_equal(array_ops.rank(target), 2),
      ["target's shape should be either [batch_size, 1] or [batch_size]"])
  with ops.control_dependencies([check_shape_op]):
    target = array_ops.reshape(target, shape=[array_ops.shape(target)[0], 1])
  return losses.hinge_loss(logits, target)
开发者ID:KalraA,项目名称:tensorflow,代码行数:7,代码来源:linear.py

示例6: _softmax_cross_entropy_loss

def _softmax_cross_entropy_loss(logits, target):
  check_shape_op = control_flow_ops.Assert(
      math_ops.less_equal(array_ops.rank(target), 2),
      ["target's shape should be either [batch_size, 1] or [batch_size]"])
  with ops.control_dependencies([check_shape_op]):
    target = array_ops.reshape(target, shape=[array_ops.shape(target)[0]])
  return nn.sparse_softmax_cross_entropy_with_logits(logits, target)
开发者ID:KalraA,项目名称:tensorflow,代码行数:7,代码来源:linear.py

示例7: testPositive

 def testPositive(self):
   n = int(10e3)
   for dt in [dtypes.float16, dtypes.float32, dtypes.float64]:
     with self.cached_session():
       x = random_ops.random_gamma(shape=[n], alpha=0.001, dtype=dt, seed=0)
       self.assertEqual(0, math_ops.reduce_sum(math_ops.cast(
           math_ops.less_equal(x, 0.), dtype=dtypes.int64)).eval())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:7,代码来源:random_gamma_test.py

示例8: assert_close

def assert_close(
    x, y, data=None, summarize=None, message=None, name="assert_close"):
  """Assert that that x and y are within machine epsilon of each other.

  Args:
    x: Numeric `Tensor`
    y: Numeric `Tensor`
    data: The tensors to print out if the condition is `False`. Defaults to
      error message and first few entries of `x` and `y`.
    summarize: Print this many entries of each tensor.
    message: A string to prefix to the default message.
    name: A name for this operation (optional).

  Returns:
    Op raising `InvalidArgumentError` if |x - y| > machine epsilon.
  """
  message = message or ""
  x = ops.convert_to_tensor(x, name="x")
  y = ops.convert_to_tensor(y, name="y")

  if x.dtype.is_integer:
    return check_ops.assert_equal(
        x, y, data=data, summarize=summarize, message=message, name=name)

  with ops.name_scope(name, "assert_close", [x, y, data]):
    tol = np.finfo(x.dtype.as_numpy_dtype).resolution
    if data is None:
      data = [
          message,
          "Condition x ~= y did not hold element-wise: x = ", x.name, x, "y = ",
          y.name, y
      ]
    condition = math_ops.reduce_all(math_ops.less_equal(math_ops.abs(x-y), tol))
    return control_flow_ops.Assert(
        condition, data, summarize=summarize)
开发者ID:Nishant23,项目名称:tensorflow,代码行数:35,代码来源:distribution_util.py

示例9: loss_fn

 def loss_fn(logits, labels):
   check_shape_op = control_flow_ops.Assert(
       math_ops.less_equal(array_ops.rank(labels), 2),
       ["labels shape should be either [batch_size, 1] or [batch_size]"])
   with ops.control_dependencies([check_shape_op]):
     labels = array_ops.reshape(
         labels, shape=[array_ops.shape(labels)[0], 1])
   return losses.hinge_loss(logits, labels)
开发者ID:HKUST-SING,项目名称:tensorflow,代码行数:8,代码来源:head.py

示例10: _log_loss_with_two_classes

def _log_loss_with_two_classes(logits, target):
  check_shape_op = control_flow_ops.Assert(
      math_ops.less_equal(array_ops.rank(target), 2),
      ["target's shape should be either [batch_size, 1] or [batch_size]"])
  with ops.control_dependencies([check_shape_op]):
    target = array_ops.reshape(target, shape=[array_ops.shape(target)[0], 1])
  return nn.sigmoid_cross_entropy_with_logits(
      logits, math_ops.to_float(target))
开发者ID:KalraA,项目名称:tensorflow,代码行数:8,代码来源:linear.py

示例11: _loss_fn

 def _loss_fn(logits, labels):
   with ops.name_scope(None, "hinge_loss", (logits, labels)) as name:
     check_shape_op = control_flow_ops.Assert(
         math_ops.less_equal(array_ops.rank(labels), 2),
         ("labels shape should be either [batch_size, 1] or [batch_size]",))
     with ops.control_dependencies((check_shape_op,)):
       labels = array_ops.reshape(
           labels, shape=(array_ops.shape(labels)[0], 1))
     return losses.hinge_loss(logits, labels, scope=name)
开发者ID:RapidApplicationDevelopment,项目名称:tensorflow,代码行数:9,代码来源:head.py

示例12: loop_body

 def loop_body(loop_count, cdf):
   temp = math_ops.reduce_sum(
       math_ops.cast(
           math_ops.less_equal(indices, loop_count), dtypes.float32))
   cdf = math_ops.add(
       cdf,
       array_ops.one_hot(
           loop_count, depth=nbins, on_value=temp, off_value=0.0))
   return [loop_count + 1, cdf]
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:9,代码来源:pruning_utils.py

示例13: _reshape_targets

def _reshape_targets(targets):
  if targets is None:
    return None
  check_shape_op = control_flow_ops.Assert(
      math_ops.less_equal(array_ops.rank(targets), 2),
      ["target's should be either [batch_size, n_labels] or [batch_size]"])
  with ops.control_dependencies([check_shape_op]):
    targets = array_ops.reshape(
        targets, shape=[array_ops.shape(targets)[0], -1])
  return targets
开发者ID:KalraA,项目名称:tensorflow,代码行数:10,代码来源:dnn_sampled_softmax_classifier.py

示例14: _reshape_targets

def _reshape_targets(targets):
  """"Reshapes targets into [batch_size, 1] to be compatible with logits."""
  check_shape_op = control_flow_ops.Assert(
      math_ops.less_equal(array_ops.rank(targets), 2),
      ["targets shape should be either [batch_size, 1] or [batch_size]"])
  with ops.control_dependencies([check_shape_op]):
    targets = array_ops.reshape(targets,
                                shape=[array_ops.shape(targets)[0], 1])

  return targets
开发者ID:MrCrumpets,项目名称:tensorflow,代码行数:10,代码来源:dnn.py

示例15: _assert_close

def _assert_close(x, y, data=None, summarize=None, name=None):
    if x.dtype.is_integer:
        return check_ops.assert_equal(x, y, data=data, summarize=summarize, name=name)

    with ops.op_scope([x, y, data], name, "assert_close"):
        x = ops.convert_to_tensor(x, name="x")
        y = ops.convert_to_tensor(y, name="y")
        tol = np.finfo(x.dtype.as_numpy_dtype).resolution
        if data is None:
            data = ["Condition x ~= y did not hold element-wise: x = ", x.name, x, "y = ", y.name, y]
        condition = math_ops.reduce_all(math_ops.less_equal(math_ops.abs(x - y), tol))
        return logging_ops.Assert(condition, data, summarize=summarize)
开发者ID:ChaitanyaCixLive,项目名称:tensorflow,代码行数:12,代码来源:dirichlet.py


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