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


Python tensorflow.linspace方法代碼示例

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


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

示例1: locationPE

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def locationPE(h, w, dim, outDim = -1, addBias = True):    
    x = tf.expand_dims(tf.to_float(tf.linspace(-config.locationBias, config.locationBias, w)), axis = -1)
    y = tf.expand_dims(tf.to_float(tf.linspace(-config.locationBias, config.locationBias, h)), axis = -1)
    i = tf.expand_dims(tf.to_float(tf.range(dim)), axis = 0)

    peSinX = tf.sin(x / (tf.pow(10000.0, i / dim)))
    peCosX = tf.cos(x / (tf.pow(10000.0, i / dim)))
    peSinY = tf.sin(y / (tf.pow(10000.0, i / dim)))
    peCosY = tf.cos(y / (tf.pow(10000.0, i / dim)))

    peSinX = tf.tile(tf.expand_dims(peSinX, axis = 0), [h, 1, 1])
    peCosX = tf.tile(tf.expand_dims(peCosX, axis = 0), [h, 1, 1])
    peSinY = tf.tile(tf.expand_dims(peSinY, axis = 1), [1, w, 1])
    peCosY = tf.tile(tf.expand_dims(peCosY, axis = 1), [1, w, 1]) 

    grid = tf.concat([peSinX, peCosX, peSinY, peCosY], axis = -1)
    dim *= 4
    
    if outDim > 0:
        grid = linear(grid, dim, outDim, addBias = addBias, name = "locationPE")
        dim = outDim

    return grid, dim 
開發者ID:stanfordnlp,項目名稱:mac-network,代碼行數:25,代碼來源:ops.py

示例2: _perspective_correct_barycentrics

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def _perspective_correct_barycentrics(vertices_per_pixel, model_to_eye_matrix,
                                      perspective_matrix, image_size_float):
  """Creates the pixels grid and computes barycentrics."""
  # Construct the pixel grid with half-integer pixel centers.
  width = image_size_float[1]
  height = image_size_float[0]
  px = tf.linspace(0.5, width - 0.5, num=int(width))
  py = tf.linspace(0.5, height - 0.5, num=int(height))
  xv, yv = tf.meshgrid(px, py)
  pixel_position = tf.stack((xv, yv), axis=-1)

  return glm.perspective_correct_barycentrics(vertices_per_pixel,
                                              pixel_position,
                                              model_to_eye_matrix,
                                              perspective_matrix,
                                              (width, height)) 
開發者ID:tensorflow,項目名稱:graphics,代碼行數:18,代碼來源:triangle_rasterizer.py

示例3: _grid

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def _grid(starts, stops, nums):
  """Generates a M-D uniform axis-aligned grid.

  Warning:
    This op is not differentiable. Indeed, the gradient of tf.linspace and
    tf.meshgrid are currently not defined.

  Args:
    starts: A tensor of shape `[M]` representing the start points for each
      dimension.
    stops: A tensor of shape `[M]` representing the end points for each
      dimension.
    nums: A tensor of shape `[M]` representing the number of subdivisions for
      each dimension.

  Returns:
    A tensor of shape `[nums[0], ..., nums[M-1], M]` containing an M-D uniform
      grid.
  """
  params = [tf.unstack(tensor) for tensor in [starts, stops, nums]]
  layout = [tf.linspace(*param) for param in zip(*params)]
  return tf.stack(tf.meshgrid(*layout, indexing="ij"), axis=-1) 
開發者ID:tensorflow,項目名稱:graphics,代碼行數:24,代碼來源:grid.py

示例4: meshgrid

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def meshgrid(batch, height, width, is_homogeneous=True):
    """Construct a 2D meshgrid.

    Args:
      batch: batch size
      height: height of the grid
      width: width of the grid
      is_homogeneous: whether to return in homogeneous coordinates
    Returns:
      x,y grid coordinates [batch, 2 (3 if homogeneous), height, width]
    """
    x_t = tf.matmul(tf.ones(shape=tf.stack([height, 1])),
                    tf.transpose(tf.expand_dims(
                        tf.linspace(-1.0, 1.0, width), 1), [1, 0]))
    y_t = tf.matmul(tf.expand_dims(tf.linspace(-1.0, 1.0, height), 1),
                    tf.ones(shape=tf.stack([1, width])))
    x_t = (x_t + 1.0) * 0.5 * tf.cast(width - 1, tf.float32)
    y_t = (y_t + 1.0) * 0.5 * tf.cast(height - 1, tf.float32)
    if is_homogeneous:
        ones = tf.ones_like(x_t)
        coords = tf.stack([x_t, y_t, ones], axis=0)
    else:
        coords = tf.stack([x_t, y_t], axis=0)
    coords = tf.tile(tf.expand_dims(coords, 0), [batch, 1, 1, 1])
    return coords 
開發者ID:hlzz,項目名稱:DeepMatchVO,代碼行數:27,代碼來源:geo_utils.py

示例5: meshgrid

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def meshgrid(self, height, width, ones_flag=None):
        # get the mesh-grid in a special area(-1,1)
        # output:
        #   @shape --> 2,H*W
        #   @explanation --> (0,:) means all x-coordinate in a mesh
        #                    (1,:) means all y-coordinate in a mesh
        with tf.variable_scope('meshgrid'):
            y_linspace = tf.linspace(-1., 1., height)
            x_linspace = tf.linspace(-1., 1., width)
            x_coordinates, y_coordinates = tf.meshgrid(x_linspace, y_linspace)
            x_coordinates = tf.reshape(x_coordinates, shape=[-1])
            y_coordinates = tf.reshape(y_coordinates, shape=[-1])
            if ones_flag is None:
                indices_grid = tf.stack([x_coordinates, y_coordinates], axis=0)
            else:
                indices_grid = tf.stack([x_coordinates, y_coordinates, tf.ones_like(x_coordinates)], axis=0)
            return indices_grid 
開發者ID:BlueWinters,項目名稱:DeepWarp,代碼行數:19,代碼來源:model.py

示例6: meshgrid

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def meshgrid(batch, height, width, is_homogeneous=True):
  """Construct a 2D meshgrid.
  Args:
    batch: batch size
    height: height of the grid
    width: width of the grid
    is_homogeneous: whether to return in homogeneous coordinates
  Returns:
    x,y grid coordinates [batch, 2 (3 if homogeneous), height, width]
  """
  x_t = tf.matmul(tf.ones(shape=tf.stack([height, 1])),
                  tf.transpose(tf.expand_dims(
                      tf.linspace(-1.0, 1.0, width), 1), [1, 0]))
  y_t = tf.matmul(tf.expand_dims(tf.linspace(-1.0, 1.0, height), 1),
                  tf.ones(shape=tf.stack([1, width])))
  x_t = (x_t + 1.0) * 0.5 * tf.cast(width - 1, tf.float32)
  y_t = (y_t + 1.0) * 0.5 * tf.cast(height - 1, tf.float32)
  if is_homogeneous:
    ones = tf.ones_like(x_t)
    coords = tf.stack([x_t, y_t, ones], axis=0)
  else:
    coords = tf.stack([x_t, y_t], axis=0)
  coords = tf.tile(tf.expand_dims(coords, 0), [batch, 1, 1, 1])
  return coords 
開發者ID:FangGet,項目名稱:tf-monodepth2,代碼行數:26,代碼來源:tools.py

示例7: _meshgrid

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def _meshgrid(height, width):
    with tf.variable_scope('_meshgrid'):
        # This should be equivalent to:
        #  x_t, y_t = np.meshgrid(np.linspace(-1, 1, width),
        #                         np.linspace(-1, 1, height))
        #  ones = np.ones(np.prod(x_t.shape))
        #  grid = np.vstack([x_t.flatten(), y_t.flatten(), ones])
        x_t = tf.matmul(tf.ones(shape=tf.stack([height, 1])),
                        tf.transpose(tf.expand_dims(tf.linspace(-1.0, 1.0, width), 1), [1, 0]))
        y_t = tf.matmul(tf.expand_dims(tf.linspace(-1.0, 1.0, height), 1),
                        tf.ones(shape=tf.stack([1, width])))

        x_t_flat = tf.reshape(x_t, (1, -1))
        y_t_flat = tf.reshape(y_t, (1, -1))

        ones = tf.ones_like(x_t_flat)
        grid = tf.concat(axis=0, values=[x_t_flat, y_t_flat, ones])
        return grid 
開發者ID:YutingZhang,項目名稱:lmdis-rep,代碼行數:20,代碼來源:spatial_transformer.py

示例8: get_actors_epsilon

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def get_actors_epsilon(actor_ids, num_training_actors, num_eval_actors,
                       eval_epsilon):
  """Per-actor epsilon as in Apex and R2D2.

  Args:
    actor_ids: <int32>[inference_batch_size], the actor task IDs (in range
      [0, num_training_actors+num_eval_actors)).
    num_training_actors: Number of training actors. Training actors should have
      IDs in [0, num_training_actors).
    num_eval_actors: Number of evaluation actors. Eval actors should have IDs in
      [num_training_actors, num_training_actors + num_eval_actors).
    eval_epsilon: Epsilon used for eval actors.

  Returns:
    A 1D float32 tensor with one epsilon for each input actor ID.
  """
  # <float32>[num_training_actors + num_eval_actors]
  epsilons = tf.concat(
      [tf.math.pow(0.4, tf.linspace(1., 8., num=num_training_actors)),
       tf.constant([eval_epsilon] * num_eval_actors)],
      axis=0)
  return tf.gather(epsilons, actor_ids) 
開發者ID:google-research,項目名稱:seed_rl,代碼行數:24,代碼來源:learner.py

示例9: _mgrid

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def _mgrid(self, *args, **kwargs):
        """
        create orthogonal grid
        similar to np.mgrid
        Parameters
        ----------
        args : int
            number of points on each axis
        low : float
            minimum coordinate value
        high : float
            maximum coordinate value
        Returns
        -------
        grid : tf.Tensor [len(args), args[0], ...]
            orthogonal grid
        """
        low = kwargs.pop("low", -1)
        high = kwargs.pop("high", 1)
        low = tf.to_float(low)
        high = tf.to_float(high)
        coords = (tf.linspace(low, high, arg) for arg in args)
        grid = tf.stack(tf.meshgrid(*coords, indexing='ij'))

        return grid 
開發者ID:xulabs,項目名稱:aitom,代碼行數:27,代碼來源:RigidTransformation3DImputation.py

示例10: meshgrid

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def meshgrid(height, width):
    with tf.variable_scope('_meshgrid'):
        # This should be equivalent to:
        #  x_t, y_t = np.meshgrid(np.linspace(-1, 1, width),
        #                         np.linspace(-1, 1, height))
        #  ones = np.ones(np.prod(x_t.shape))
        #  grid = np.vstack([x_t.flatten(), y_t.flatten(), ones])

        # with tf.device('/cpu:0'):
        #     x_t = tf.matmul(tf.ones(shape=tf.pack([height, 1])),
        #                     tf.transpose(tf.expand_dims(tf.linspace(0.0, -1.0 + width, width), 1), [1, 0]))
        #     y_t = tf.matmul(tf.expand_dims(tf.linspace(0.0, -1.0 + height, height), 1),
        #                     tf.ones(shape=tf.pack([1, width])))
        # x_t = tf.expand_dims(x_t, 2)
        # y_t = tf.expand_dims(y_t, 2)
        # grid = tf.concat(2, [x_t, y_t])
        with tf.device('/cpu:0'):
            grid = tf.meshgrid(list(range(height)), list(range(width)), indexing='ij')
            grid = tf.cast(tf.stack(grid, axis=2)[:, :, ::-1], tf.float32)
    return grid 
開發者ID:psychopa4,項目名稱:PFNL,代碼行數:22,代碼來源:videosr_ops.py

示例11: meshgrid_abs

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def meshgrid_abs(batch, height, width, is_homogeneous=True):
  """Construct a 2D meshgrid in the absolute coordinates.

  Args:
    batch: batch size
    height: height of the grid
    width: width of the grid
    is_homogeneous: whether to return in homogeneous coordinates
  Returns:
    x,y grid coordinates [batch, 2 (3 if homogeneous), height, width]
  """
  xs = tf.linspace(0.0, tf.cast(width-1, tf.float32), width)
  ys = tf.linspace(0.0, tf.cast(height-1, tf.float32), height)
  xs, ys = tf.meshgrid(xs, ys)

  if is_homogeneous:
    ones = tf.ones_like(xs)
    coords = tf.stack([xs, ys, ones], axis=0)
  else:
    coords = tf.stack([xs, ys], axis=0)
  coords = tf.tile(tf.expand_dims(coords, 0), [batch, 1, 1, 1])
  return coords 
開發者ID:google,項目名稱:stereo-magnification,代碼行數:24,代碼來源:projector.py

示例12: rot_mat_uniform

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def rot_mat_uniform(phi0, phi1, phi_unit, theta0, theta1, theta_unit):
    if phi_unit == 0:
        phi = [(phi1-phi0)/2]
    else:
        n_phi = np.abs(phi1-phi0) / float(phi_unit) + 1
        phi = np.linspace(phi0, phi1, n_phi, endpoint=True)

    if theta_unit == 0:
        theta = [(theta1-theta0)/2]
    else:
        n_theta = np.abs(theta1-theta0) / float(theta_unit) + 1
        theta = np.linspace(theta0, theta1, n_theta, endpoint=True)    

    views = []
    for phi_ in phi:
        for theta_ in theta:
            views.append({'phi':phi_, 'theta':theta_})

    return views 
開發者ID:byungsook,項目名稱:neural-flow-style,代碼行數:21,代碼來源:transform.py

示例13: _grid_norm

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def _grid_norm(width, height, bounds=(-1.0, 1.0)):
  """generate a normalized mesh grid

    Args:
        width: width of the pixels(mesh)
        height: height of the pixels
        bounds: normalized lower and upper bounds
    Return:
        This should be equivalent to:
        >>>  x_t, y_t = np.meshgrid(np.linspace(-1, 1, width),
        >>>                         np.linspace(-1, 1, height))
        >>>  ones = np.ones(np.prod(x_t.shape))
        >>>  grid = np.vstack([x_t.flatten(), y_t.flatten(), ones])
  """
  x_t = tf.matmul(tf.ones(shape=tf.stack([height, 1])),
                  tf.transpose(tf.expand_dims(
                      tf.linspace(*bounds, width), 1), [1, 0]))
  y_t = tf.matmul(tf.expand_dims(tf.linspace(*bounds, height), 1),
                  tf.ones(shape=tf.stack([1, width])))

  grid = tf.stack([x_t, y_t], axis=-1)
  return grid 
開發者ID:LoSealL,項目名稱:VideoSuperResolution,代碼行數:24,代碼來源:Motion.py

示例14: create_decoder

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def create_decoder(self, features):
        with tf.variable_scope('decoder', reuse=tf.AUTO_REUSE):
            coarse = mlp(features, [1024, 1024, self.num_coarse * 3])
            coarse = tf.reshape(coarse, [-1, self.num_coarse, 3])

        with tf.variable_scope('folding', reuse=tf.AUTO_REUSE):
            grid = tf.meshgrid(tf.linspace(-0.05, 0.05, self.grid_size), tf.linspace(-0.05, 0.05, self.grid_size))
            grid = tf.expand_dims(tf.reshape(tf.stack(grid, axis=2), [-1, 2]), 0)
            grid_feat = tf.tile(grid, [features.shape[0], self.num_coarse, 1])

            point_feat = tf.tile(tf.expand_dims(coarse, 2), [1, 1, self.grid_size ** 2, 1])
            point_feat = tf.reshape(point_feat, [-1, self.num_fine, 3])

            global_feat = tf.tile(tf.expand_dims(features, 1), [1, self.num_fine, 1])

            feat = tf.concat([grid_feat, point_feat, global_feat], axis=2)

            center = tf.tile(tf.expand_dims(coarse, 2), [1, 1, self.grid_size ** 2, 1])
            center = tf.reshape(center, [-1, self.num_fine, 3])

            fine = mlp_conv(feat, [512, 512, 3]) + center
        return coarse, fine 
開發者ID:wentaoyuan,項目名稱:pcn,代碼行數:24,代碼來源:pcn_cd.py

示例15: create_decoder

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import linspace [as 別名]
def create_decoder(self, features):
        with tf.variable_scope('decoder', reuse=tf.AUTO_REUSE):
            coarse = mlp(features, [1024, 1024, self.num_coarse * 3])
            coarse = tf.reshape(coarse, [-1, self.num_coarse, 3])

        with tf.variable_scope('folding', reuse=tf.AUTO_REUSE):
            x = tf.linspace(-self.grid_scale, self.grid_scale, self.grid_size)
            y = tf.linspace(-self.grid_scale, self.grid_scale, self.grid_size)
            grid = tf.meshgrid(x, y)
            grid = tf.expand_dims(tf.reshape(tf.stack(grid, axis=2), [-1, 2]), 0)
            grid_feat = tf.tile(grid, [features.shape[0], self.num_coarse, 1])

            point_feat = tf.tile(tf.expand_dims(coarse, 2), [1, 1, self.grid_size ** 2, 1])
            point_feat = tf.reshape(point_feat, [-1, self.num_fine, 3])

            global_feat = tf.tile(tf.expand_dims(features, 1), [1, self.num_fine, 1])

            feat = tf.concat([grid_feat, point_feat, global_feat], axis=2)

            center = tf.tile(tf.expand_dims(coarse, 2), [1, 1, self.grid_size ** 2, 1])
            center = tf.reshape(center, [-1, self.num_fine, 3])

            fine = mlp_conv(feat, [512, 512, 3]) + center
        return coarse, fine 
開發者ID:wentaoyuan,項目名稱:pcn,代碼行數:26,代碼來源:pcn_emd.py


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