本文整理汇总了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
示例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))
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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