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


Python tensorflow.less函数代码示例

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


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

示例1: enc_step

 def enc_step(step):
   """Encoder step."""
   if autoenc_decay < 1.0:
     quant_step = autoenc_quantize(step, 16, nmaps, self.do_training)
     if backward:
       exp_glob = tf.train.exponential_decay(1.0, self.global_step - 10000,
                                             1000, autoenc_decay)
       dec_factor = 1.0 - exp_glob  # * self.do_training
       dec_factor = tf.cond(tf.less(self.global_step, 10500),
                            lambda: tf.constant(0.05), lambda: dec_factor)
     else:
       dec_factor = 1.0
     cur = tf.cond(tf.less(tf.random_uniform([]), dec_factor),
                   lambda: quant_step, lambda: step)
   else:
     cur = step
   if dropout > 0.0001:
     cur = tf.nn.dropout(cur, keep_prob)
   if act_noise > 0.00001:
     cur += tf.truncated_normal(tf.shape(cur)) * act_noise_scale
   # Do nconvs-many CGRU steps.
   if do_jit and tf.get_variable_scope().reuse:
     with jit_scope():
       for layer in xrange(nconvs):
         cur = conv_gru([], cur, kw, kh, nmaps, conv_rate(layer),
                        cutoff, "ecgru_%d" % layer, do_layer_norm)
   else:
     for layer in xrange(nconvs):
       cur = conv_gru([], cur, kw, kh, nmaps, conv_rate(layer),
                      cutoff, "ecgru_%d" % layer, do_layer_norm)
   return cur
开发者ID:Jmq14,项目名称:models,代码行数:31,代码来源:neural_gpu.py

示例2: set_logp_to_neg_inf

def set_logp_to_neg_inf(X, logp, bounds):
    """Set `logp` to negative infinity when `X` is outside the allowed bounds.

    # Arguments
        X: tensorflow.Tensor
            The variable to apply the bounds to
        logp: tensorflow.Tensor
            The log probability corrosponding to `X`
        bounds: list of `Region` objects
            The regions corrosponding to allowed regions of `X`

    # Returns
        logp: tensorflow.Tensor
            The newly bounded log probability
    """
    conditions = []
    for l, u in bounds:
        lower_is_neg_inf = not isinstance(l, tf.Tensor) and np.isneginf(l)
        upper_is_pos_inf = not isinstance(u, tf.Tensor) and np.isposinf(u)

        if not lower_is_neg_inf and upper_is_pos_inf:
            conditions.append(tf.greater(X, l))
        elif lower_is_neg_inf and not upper_is_pos_inf:
            conditions.append(tf.less(X, u))
        elif not (lower_is_neg_inf or upper_is_pos_inf):
            conditions.append(tf.logical_and(tf.greater(X, l), tf.less(X, u)))

    if len(conditions) > 0:
        is_inside_bounds = conditions[0]
        for condition in conditions[1:]:
            is_inside_bounds = tf.logical_or(is_inside_bounds, condition)

        logp = tf.select(is_inside_bounds, logp, tf.fill(tf.shape(X), config.dtype(-np.inf)))

    return logp
开发者ID:tensorprob,项目名称:tensorprob,代码行数:35,代码来源:utilities.py

示例3: prune_outside_window

def prune_outside_window(boxlist, window, scope=None):
  """Prunes bounding boxes that fall outside a given window.

  This function prunes bounding boxes that even partially fall outside the given
  window. See also clip_to_window which only prunes bounding boxes that fall
  completely outside the window, and clips any bounding boxes that partially
  overflow.

  Args:
    boxlist: a BoxList holding M_in boxes.
    window: a float tensor of shape [4] representing [ymin, xmin, ymax, xmax]
      of the window
    scope: name scope.

  Returns:
    pruned_corners: a tensor with shape [M_out, 4] where M_out <= M_in
    valid_indices: a tensor with shape [M_out] indexing the valid bounding boxes
     in the input tensor.
  """
  with tf.name_scope(scope, 'PruneOutsideWindow'):
    y_min, x_min, y_max, x_max = tf.split(
        value=boxlist.get(), num_or_size_splits=4, axis=1)
    win_y_min, win_x_min, win_y_max, win_x_max = tf.unstack(window)
    coordinate_violations = tf.concat([
        tf.less(y_min, win_y_min), tf.less(x_min, win_x_min),
        tf.greater(y_max, win_y_max), tf.greater(x_max, win_x_max)
    ], 1)
    valid_indices = tf.reshape(
        tf.where(tf.logical_not(tf.reduce_any(coordinate_violations, 1))), [-1])
    return gather(boxlist, valid_indices), valid_indices
开发者ID:NoPointExc,项目名称:models,代码行数:30,代码来源:box_list_ops.py

示例4: compute_IOU

def compute_IOU(bboxA, bboxB):
    """Compute the Intersection Over Union.
    Args:
        bboxA: [N X 4 tensor] format = [left, top, right, bottom]
        bboxB: [N X 4 tensor] 

    Return:
        IOU: [N X 1 tensor]
    """

    x1A, y1A, x2A, y2A = tf.split(1, 4, bboxA)
    x1B, y1B, x2B, y2B = tf.split(1, 4, bboxB)

    # compute intersection
    x1_max = tf.maximum(x1A, x1B)
    y1_max = tf.maximum(y1A, y1B)
    x2_min = tf.minimum(x2A, x2B)
    y2_min = tf.minimum(y2A, y2B)

    # overlap_flag = tf.logical_and( tf.less(x1_max, x2_min), tf.less(y1_max, y2_min))

    overlap_flag = tf.to_float(tf.less(x1_max, x2_min)) * \
        tf.to_float(tf.less(y1_max, y2_min))

    overlap_area = tf.mul(overlap_flag, tf.mul(
        x2_min - x1_max, y2_min - y1_max))

    # compute union
    areaA = tf.mul(x2A - x1A, y2A - y1A)
    areaB = tf.mul(x2B - x1B, y2B - y1B)
    union_area = areaA + areaB - overlap_area

    return tf.div(overlap_area, union_area)
开发者ID:renmengye,项目名称:deep-tracker,代码行数:33,代码来源:build_deep_tracker.py

示例5: loop

        def loop(step_, beams_, beam_value_, golden_value_, golden_inside_, step_valid_, g_id_, golden_record, beam_record):
            cur_feat_x_ = tf.gather(x, step_)
            cur_golden_path_ = tf.gather(golden_path, tf.range(step_))
            cur_golden_feat_ = self._add_tag_dynamic(cur_feat_x_, cur_golden_path_)
            # cur_golden_output_ = self._build_cnn(cur_golden_feat_)
            cur_golden_output_ = build(cur_golden_feat_)
            cur_golden_node_ = tf.gather(golden_path, tf.reshape(step_, [1]))
            golden_value_ = tf.add(golden_value_,
                                  tf.slice(cur_golden_output_, tf.concat(0, [[0], cur_golden_node_]), [1, 1]))

            cur_beam_ = tf.unpack(beams_, num=self.beam_size)
            cur_beam_feat_ = tf.concat(0, [self._add_tag_dynamic(cur_feat_x_, tf.reshape(e, [-1])) for e in cur_beam_])
            # cur_beam_output_ = self._build_cnn(cur_beam_feat_)
            cur_beam_output_ = build(cur_beam_feat_)

            golden_record = golden_record.write(step_, cur_golden_output_)
            beam_record = beam_record.write(step_, cur_beam_output_)

            beam_value_, beams_ = self._top_beams_new(cur_beam_output_, beam_value_, beams_)
            new_golden_path_ = tf.gather(golden_path, tf.range(step_ + 1))
            # golden_beam_id_ = index_of_tensor(new_golden_path_, beams_)
            g_id_ = index_of_tensor(new_golden_path_, beams_)
            golden_inside_ = tf.select(tf.less(tf.shape(g_id_)[0], 1),
                                       tf.constant(False, tf.bool), tf.constant(True, tf.bool))

            step_valid_ = tf.logical_and(tf.less(step_+1, length), tf.less(step_+1, self.max_step_tracked))
            return [step_ + 1, beams_, beam_value_, golden_value_, golden_inside_, step_valid_, g_id_, golden_record, beam_record]
开发者ID:staylonging,项目名称:tf,代码行数:27,代码来源:cnnglobal.py

示例6: l1_smooth_losses

def l1_smooth_losses(predict_boxes, gtboxes, object_weights, classes_weights=None):
    '''

    :param predict_boxes: [minibatch_size, -1]
    :param gtboxes: [minibatch_size, -1]
    :param object_weights: [minibatch_size, ]. 1.0 represent object, 0.0 represent others(ignored or background)
    :return:
    '''

    diff = predict_boxes - gtboxes
    abs_diff = tf.cast(tf.abs(diff), tf.float32)

    if classes_weights is None:
        '''
        first_stage:
        predict_boxes :[minibatch_size, 5]
        gtboxes: [minibatchs_size, 5]
        '''
        anchorwise_smooth_l1norm = tf.reduce_sum(
            tf.where(tf.less(abs_diff, 1), 0.5 * tf.square(abs_diff), abs_diff - 0.5),
            axis=1) * object_weights
    else:
        '''
        fast_rcnn stage:
        predict_boxes: [minibatch_size, 5*num_classes]
        gtboxes: [minibatch_size, 5*num_classes]
        classes_weights : [minibatch_size, 5*num_classes]
        '''
        anchorwise_smooth_l1norm = tf.reduce_sum(
            tf.where(tf.less(abs_diff, 1), 0.5*tf.square(abs_diff)*classes_weights,
                     (abs_diff - 0.5)*classes_weights),
            axis=1)*object_weights
    return tf.reduce_mean(anchorwise_smooth_l1norm, axis=0)  # reduce mean
开发者ID:mbossX,项目名称:RRPN_FPN_Tensorflow,代码行数:33,代码来源:losses.py

示例7: image_distortions

def image_distortions(image, distortions):
    distort_left_right_random = distortions[0]
    mirror = tf.less(tf.pack([1.0, distort_left_right_random, 1.0]), 0.5)
    image = tf.reverse(image, mirror)
    distort_up_down_random = distortions[1]
    mirror = tf.less(tf.pack([distort_up_down_random, 1.0, 1.0]), 0.5)
    image = tf.reverse(image, mirror)
    return image
开发者ID:mtourne,项目名称:nerveseg,代码行数:8,代码来源:nerveseg_input.py

示例8: learning_rate_schedule

def learning_rate_schedule():  # Function which controls learning rate during training
  import tensorflow as tf
  step = tf.train.get_or_create_global_step()
  lr = tf.case([(tf.less(step,  1000), lambda: tf.constant(0.0004)),
                (tf.less(step, 10000), lambda: tf.constant(0.01)),
                (tf.less(step, 40000), lambda: tf.constant(0.005)),
                (tf.less(step, 55000), lambda: tf.constant(0.0005)),
                (tf.less(step, 65000), lambda: tf.constant(0.00005))])
  return lr
开发者ID:undeadinu,项目名称:training_toolbox_tensorflow,代码行数:9,代码来源:config.py

示例9: testWhileCond_3

    def testWhileCond_3(self):
        with self.test_session():
            n = tf.convert_to_tensor(0)
            c = lambda x: tf.less(x, 10)
            b = lambda x: control_flow_ops.cond(tf.less(0, 1), lambda: tf.add(x, 1), lambda: tf.sub(x, 1))
            r = control_flow_ops.While(c, b, [n])

            result = r.eval()
        self.assertTrue(check_op_order(n.graph))
        self.assertAllEqual(10, result)
开发者ID:peace195,项目名称:tensorflow,代码行数:10,代码来源:control_flow_ops_py_test.py

示例10: bottleneck

 def bottleneck(self, x):
   hparams = self.hparams
   x = tf.tanh(tf.layers.dense(x, hparams.bottleneck_bits, name="bottleneck"))
   d = x + tf.stop_gradient(2.0 * tf.to_float(tf.less(0.0, x)) - 1.0 - x)
   if hparams.mode == tf.estimator.ModeKeys.TRAIN:
     noise = tf.random_uniform(common_layers.shape_list(x))
     noise = 2.0 * tf.to_float(tf.less(hparams.bottleneck_noise, noise)) - 1.0
     d *= noise
   x = common_layers.mix(d, x, hparams.discretize_warmup_steps,
                         hparams.mode == tf.estimator.ModeKeys.TRAIN)
   return x, 0.0
开发者ID:kltony,项目名称:tensor2tensor,代码行数:11,代码来源:autoencoders.py

示例11: augment_2d

def augment_2d(inputs, rotation=0, horizontal_flip=False, vertical_flip=False):
    """Apply additive augmentation on 2D data.

    # Arguments
      rotation: A float, the degree range for rotation (0 <= rotation < 180),
          e.g. 3 for random image rotation between (-3.0, 3.0).
      horizontal_flip: A boolean, whether to allow random horizontal flip,
          e.g. true for 50% possibility to flip image horizontally.
      vertical_flip: A boolean, whether to allow random vertical flip,
          e.g. true for 50% possibility to flip image vertically.

    # Returns
      input data after augmentation, whose shape is the same as its original.
    """
    if inputs.dtype != tf.float32:
        inputs = tf.image.convert_image_dtype(inputs, dtype=tf.float32)

    with tf.name_scope('augmentation'):
        shp = tf.shape(inputs)
        batch_size, height, width = shp[0], shp[1], shp[2]
        width = tf.cast(width, tf.float32)
        height = tf.cast(height, tf.float32)

        transforms = []
        identity = tf.constant([1, 0, 0, 0, 1, 0, 0, 0], dtype=tf.float32)

        if rotation > 0:
            angle_rad = rotation * 3.141592653589793 / 180.0
            angles = tf.random_uniform([batch_size], -angle_rad, angle_rad)
            f = tf.contrib.image.angles_to_projective_transforms(angles,
                                                                 height, width)
            transforms.append(f)

        if horizontal_flip:
            coin = tf.less(tf.random_uniform([batch_size], 0, 1.0), 0.5)
            shape = [-1., 0., width, 0., 1., 0., 0., 0.]
            flip_transform = tf.convert_to_tensor(shape, dtype=tf.float32)
            flip = tf.tile(tf.expand_dims(flip_transform, 0), [batch_size, 1])
            noflip = tf.tile(tf.expand_dims(identity, 0), [batch_size, 1])
            transforms.append(tf.where(coin, flip, noflip))

        if vertical_flip:
            coin = tf.less(tf.random_uniform([batch_size], 0, 1.0), 0.5)
            shape = [1., 0., 0., 0., -1., height, 0., 0.]
            flip_transform = tf.convert_to_tensor(shape, dtype=tf.float32)
            flip = tf.tile(tf.expand_dims(flip_transform, 0), [batch_size, 1])
            noflip = tf.tile(tf.expand_dims(identity, 0), [batch_size, 1])
            transforms.append(tf.where(coin, flip, noflip))

    if transforms:
        f = tf.contrib.image.compose_transforms(*transforms)
        inputs = tf.contrib.image.transform(inputs, f, interpolation='BILINEAR')
    return inputs
开发者ID:Bjoux2,项目名称:keras,代码行数:53,代码来源:cifar10_cnn_tfaugment2d.py

示例12: testCondWhile_1

  def testCondWhile_1(self):
    with self.test_session():
      n = tf.convert_to_tensor(0, name="n")
      c = lambda x: tf.less(x, 10)
      b = lambda x: tf.add(x, 1)
      r = tf.cond(tf.less(0, 1),
                  lambda: control_flow_ops.While(c, b, [n]),
                  lambda: n)

      result = r.eval()
    self.assertTrue(check_op_order(n.graph))
    self.assertAllEqual(10, result)
开发者ID:hypatiad,项目名称:tensorflow,代码行数:12,代码来源:control_flow_ops_py_test.py

示例13: tanh_discrete_bottleneck

def tanh_discrete_bottleneck(x, bottleneck_bits, bottleneck_noise,
                             discretize_warmup_steps, mode):
  """Simple discretization through tanh, flip bottleneck_noise many bits."""
  x = tf.tanh(tf.layers.dense(x, bottleneck_bits,
                              name="tanh_discrete_bottleneck"))
  d = x + tf.stop_gradient(2.0 * tf.to_float(tf.less(0.0, x)) - 1.0 - x)
  if mode == tf.estimator.ModeKeys.TRAIN:
    noise = tf.random_uniform(common_layers.shape_list(x))
    noise = 2.0 * tf.to_float(tf.less(bottleneck_noise, noise)) - 1.0
    d *= noise
  d = common_layers.mix(d, x, discretize_warmup_steps,
                        mode == tf.estimator.ModeKeys.TRAIN)
  return d, 0.0
开发者ID:kltony,项目名称:tensor2tensor,代码行数:13,代码来源:discretization.py

示例14: process_features

def process_features(image, label, do_augment = False):
    # Do any image preprocessing/augmentation here...
    with tf.name_scope('process_features'):

        # Crop driving view (Start from row 126, and slice 100 rows)
        image = tf.slice(image, [126, 0, 0], [100, 256, 3])

        # Resize image
        image = tf.image.resize_images(image, [66, 200])

        if do_augment == True:
            # Change or not change colors
            def do_color_changes():
                distorted_image = tf.image.random_brightness(image, max_delta=32. / 255.)
                distorted_image = tf.image.random_saturation(distorted_image, lower=0.5, upper=1.5)
                distorted_image = tf.image.random_hue(distorted_image, max_delta=0.2)
                distorted_image = tf.image.random_contrast(distorted_image, lower=0.5, upper=1.5)
                return distorted_image

            def no_color_change():
                distorted_image = image
                return distorted_image
            # Uniform variable in [0,1)
            flip_coin_color = tf.random_uniform(shape=[], minval=0., maxval=1., dtype=tf.float32)
            pred_color = tf.less(flip_coin_color, 0.5)
            # Randomically select doing color augmentation
            image = tf.cond(pred_color, do_color_changes, no_color_change, name='if_color')

            # Change or not change colors
            def flip_image_steering():
                distorted_image = tf.image.flip_left_right(image)
                distorted_label = -label
                return distorted_image, distorted_label

            def no_flip_image_steering():
                distorted_image = image
                distorted_label = label
                return distorted_image, distorted_label
            # Uniform variable in [0,1)
            flip_coin_flip = tf.random_uniform(shape=[], minval=0., maxval=1., dtype=tf.float32)
            pred_flip = tf.less(flip_coin_flip, 0.5)
            # Randomically select doing color augmentation
            image, label = tf.cond(pred_flip, flip_image_steering, no_flip_image_steering, name='if_steering')

        # Convert from [0, 255] -> [-0.5, 0.5] floats.
        image = tf.cast(image, tf.float32) * (1. / 255.0)
        #image = tf.image.per_image_standardization(image)

    return image, label
开发者ID:leonardoaraujosantos,项目名称:DriverLessCarHackathon,代码行数:49,代码来源:model_util.py

示例15: unwrap

def unwrap(p, discont=np.pi, axis=-1):
  """Unwrap a cyclical phase tensor.

  Args:
    p: Phase tensor.
    discont: Float, size of the cyclic discontinuity.
    axis: Axis of which to unwrap.

  Returns:
    unwrapped: Unwrapped tensor of same size as input.
  """
  dd = diff(p, axis=axis)
  ddmod = tf.mod(dd + np.pi, 2.0 * np.pi) - np.pi
  idx = tf.logical_and(tf.equal(ddmod, -np.pi), tf.greater(dd, 0))
  ddmod = tf.where(idx, tf.ones_like(ddmod) * np.pi, ddmod)
  ph_correct = ddmod - dd
  idx = tf.less(tf.abs(dd), discont)
  ddmod = tf.where(idx, tf.zeros_like(ddmod), dd)
  ph_cumsum = tf.cumsum(ph_correct, axis=axis)

  shape = p.get_shape().as_list()
  shape[axis] = 1
  ph_cumsum = tf.concat([tf.zeros(shape, dtype=p.dtype), ph_cumsum], axis=axis)
  unwrapped = p + ph_cumsum
  return unwrapped
开发者ID:cghawthorne,项目名称:magenta,代码行数:25,代码来源:spectral_ops.py


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