当前位置: 首页>>代码示例>>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;未经允许,请勿转载。