本文整理汇总了Python中tensorflow.sin方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.sin方法的具体用法?Python tensorflow.sin怎么用?Python tensorflow.sin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.sin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_timing_signal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def get_timing_signal(length,
min_timescale=1,
max_timescale=1e4,
num_timescales=16):
"""Create Tensor of sinusoids of different frequencies.
Args:
length: Length of the Tensor to create, i.e. Number of steps.
min_timescale: a float
max_timescale: a float
num_timescales: an int
Returns:
Tensor of shape (length, 2*num_timescales)
"""
positions = tf.to_float(tf.range(length))
log_timescale_increment = (
math.log(max_timescale / min_timescale) / (num_timescales - 1))
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(positions, 1) * tf.expand_dims(inv_timescales, 0)
return tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
示例2: rotate_point_cloud_by_angle_y
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def rotate_point_cloud_by_angle_y(batch_data, rotation_angle):
""" Rotate the point cloud along up direction with certain angle.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
#rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[cosval, 0, sinval],
[0, 1, 0],
[-sinval, 0, cosval]])
shape_pc = batch_data[k, ...]
# rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
rotated_data[k, ...] = np.dot(rotation_matrix, shape_pc.reshape((-1, 3)).T).T # Pre-Multiplication (changes done)
return rotated_data
示例3: rotate_point_cloud_by_angle_x
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def rotate_point_cloud_by_angle_x(batch_data, rotation_angle):
""" Rotate the point cloud along up direction with certain angle.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
#rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[1, 0, 0],
[0, cosval, -sinval],
[0, sinval, cosval]])
shape_pc = batch_data[k, ...]
# rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
rotated_data[k, ...] = np.dot(rotation_matrix, shape_pc.reshape((-1, 3)).T).T # Pre-Multiplication (changes done)
return rotated_data
示例4: rotate_point_cloud_by_angle_z
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def rotate_point_cloud_by_angle_z(batch_data, rotation_angle):
""" Rotate the point cloud along up direction with certain angle.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
#rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[cosval, -sinval, 0],
[sinval, cosval, 0],
[0, 0, 1]])
shape_pc = batch_data[k, ...]
# rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
rotated_data[k, ...] = np.dot(rotation_matrix, shape_pc.reshape((-1, 3)).T).T # Pre-Multiplication (changes done)
return rotated_data
# Translate the data as per given translation vector.
示例5: locationPE
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [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
示例6: __init__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def __init__(self, position_size, hparams=None):
EmbedderBase.__init__(self, hparams=hparams)
dim = self._hparams.dim
num_timescales = dim // 2
min_timescale = self._hparams.min_timescale
max_timescale = self._hparams.max_timescale
positions = tf.to_float(tf.range(position_size, dtype=tf.int32))
log_timescale_increment = (
math.log(float(max_timescale) / float(min_timescale)) /
(tf.to_float(num_timescales) - 1))
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(positions, 1) \
* tf.expand_dims(inv_timescales, 0)
signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
signal = tf.pad(signal, [[0, 0], [0, tf.mod(dim, 2)]])
self.signal = signal
示例7: test_ODEbadprecision
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def test_ODEbadprecision(self): # make sure float32 is not enough for very precise integration
t = tf.constant(np.linspace(0, 10, 1000), dtype=tf.float32)
# initial condition
true_y0 = tf.constant([0., 5.], dtype=tf.float32)
true_func = lambda y, t: np.sin(5*t)
ode_func = lambda y, t: tf.cast(tf.stack([5*tf.cos(5*t), -25*tf.sin(5*t)]), tf.float32)
true_y = odeint(ode_func, true_y0, t, method='dop853', precision=tf.float32)
self.assertRaises(AssertionError, npt.assert_array_almost_equal, true_y.numpy()[:, 0], true_func(true_y0, t))
true_y0_pretend_multidims = [[0., 5.]] # to introduce a mix of list, np array, tensor to make sure no issue
true_y_pretend_multidims = odeint(ode_func, true_y0_pretend_multidims, t, method='dop853', precision=tf.float32)
# assert equal pretendinging multidim or not
np.testing.assert_array_almost_equal(true_y_pretend_multidims[0], true_y)
true_y0_multidims = tf.constant([[1., 2.], [0., 5.]], dtype=tf.float32)
t = np.linspace(0, 10, 1000)
true_y_multidims = odeint(ode_func, true_y0_multidims, t, method='dop853', precision=tf.float32)
# assert equal in multidim or not
np.testing.assert_array_almost_equal(true_y_multidims[1], true_y)
示例8: gaussian
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def gaussian(config, gan, net):
z_dim = net.get_shape().as_list()[-1]
net = (net + 1) / 2
if len(gan.ops.shape(net)) == 4:
za = tf.slice(net, [0,0,0,0], [gan.batch_size(), -1, -1, z_dim//2])
zb = tf.slice(net, [0,0,0,z_dim//2], [gan.batch_size(), -1, -1, z_dim//2])
else:
za = tf.slice(net, [0,0], [gan.batch_size(), z_dim//2])
zb = tf.slice(net, [0,z_dim//2], [gan.batch_size(), z_dim//2])
pi = np.pi
ra = tf.sqrt(-2 * tf.log(za+TINY))*tf.cos(2*pi*zb)
rb = tf.sqrt(-2 * tf.log(za+TINY))*tf.sin(2*pi*zb)
return tf.reshape(tf.concat(axis=len(net.get_shape())-1, values=[ra, rb]), net.get_shape())
示例9: batch_rodrigues
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def batch_rodrigues(theta, name=None):
"""
Theta is N x 3
"""
with tf.variable_scope(name, "batch_rodrigues", [theta]):
batch_size = tf.shape(theta)[0]
angle = tf.expand_dims(tf.norm(theta + 1e-8, axis=1), -1)
r = tf.expand_dims(tf.div(theta, angle), -1)
angle = tf.expand_dims(angle, -1)
cos = tf.cos(angle)
sin = tf.sin(angle)
outer = tf.matmul(r, r, transpose_b=True, name="outer")
eyes = tf.tile(tf.expand_dims(tf.eye(3), 0), [batch_size, 1, 1])
R = cos * eyes + (1 - cos) * outer + sin * batch_skew(
r, batch_size=batch_size)
return R
示例10: neural_net
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def neural_net(X, weights, biases):
num_layers = len(weights) + 1
H = X
for l in range(0,num_layers-2):
W = weights[l]
b = biases[l]
H = tf.sin(tf.add(tf.matmul(H, W), b))
W = weights[-1]
b = biases[-1]
Y = tf.add(tf.matmul(H, W), b)
return Y
###############################################################################
################################ DeepHPM Class ################################
###############################################################################
示例11: add_timing_signal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def add_timing_signal(x, scope='', min_timescale=1.0, max_timescale=1.0e4):
with tf.name_scope(scope, values=[x]):
length = tf.shape(x)[1]
channels = tf.shape(x)[2]
position = tf.to_float(tf.range(length))
num_timescales = channels // 2
log_timescale_increment = (
math.log(float(max_timescale) / float(min_timescale)) /
(tf.to_float(num_timescales) - 1)
)
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment
)
scaled_time = (tf.expand_dims(position, 1) *
tf.expand_dims(inv_timescales, 0))
signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
signal = tf.pad(signal, [[0, 0], [0, tf.mod(channels, 2)]])
signal = tf.reshape(signal, [1, length, channels])
return x + signal
示例12: get_timing_signal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def get_timing_signal(length,
min_timescale=1,
max_timescale=1e4,
num_timescales=16):
"""Create Tensor of sinusoids of different frequencies.
Args:
length: Length of the Tensor to create, i.e. Number of steps.
min_timescale: a float
max_timescale: a float
num_timescales: an int
Returns:
Tensor of shape (length, 2*num_timescales)
"""
positions = to_float(tf.range(length))
log_timescale_increment = (
math.log(max_timescale / min_timescale) / (num_timescales - 1))
inv_timescales = min_timescale * tf.exp(
to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(positions, 1) * tf.expand_dims(inv_timescales, 0)
return tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
示例13: _position_encoding
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def _position_encoding(position_size, dim,
min_timescale=1.0,
max_timescale=1.0e4):
position = tf.to_float(tf.range(position_size))
num_timescales = dim // 2
log_timescale_increment = (
math.log(float(max_timescale) / float(min_timescale)) /
(tf.to_float(num_timescales) - 1))
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(position, 1) \
* tf.expand_dims(inv_timescales, 0)
signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
signal = tf.pad(signal, [[0, 0], [0, tf.mod(dim, 2)]])
signal = tf.reshape(signal, [1, position_size, dim])
return signal
示例14: get_positional_signal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def get_positional_signal(time_steps, depth, float_dtype, min_timescale=1, max_timescale=10000):
""" Generates a series of sinusoid functions capable of expressing the relative and absolute position
of a token within a longer sequence. """
# Convert to floats
min_timescale = tf.cast(min_timescale, float_dtype)
max_timescale = tf.cast(max_timescale, float_dtype)
# Obtain timing signal via sinusoids
num_timescales = tf.cast(depth // 2, float_dtype)
log_timescale_increment = tf.math.log(max_timescale / min_timescale) / (num_timescales - tf.cast(1.0, float_dtype))
# Introduce an offset between individual timescales to obtain different frequencies
incremented_timescales = \
min_timescale * tf.exp(tf.range(num_timescales, dtype=float_dtype) * -log_timescale_increment)
# Assign the designated number of time-scales per token position
positions = tf.cast(tf.range(time_steps), float_dtype)
scaled_time = tf.expand_dims(positions, 1) * tf.expand_dims(incremented_timescales, 0)
positional_signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
# Pad the signal tensor, if needed
pad_size = depth % 2
if pad_size != 0:
tf.pad(tensor=positional_signal, paddings=[[0, 0], [0, pad_size]])
# Reshape the signal to make it compatible with the target tensor
positional_signal = tf.reshape(positional_signal, [1, time_steps, depth])
return positional_signal
示例15: transform
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sin [as 别名]
def transform(image, landmark, translation=[0, 0], rotation=0, scale=1):
"""Apply an affine transformation to the image."""
image = tf.convert_to_tensor(image)
landmark = tf.convert_to_tensor(landmark, dtype=tf.float32)
translation = tf.convert_to_tensor(translation, dtype=tf.float32)
rotation = tf.convert_to_tensor(rotation, dtype=tf.float32)
scale = tf.convert_to_tensor(scale, dtype=tf.float32)
# Generate a transformation matrix
h, w = image.shape.as_list()[-3:-1]
tx, ty = tf.unstack(translation, axis=-1)
sc = tf.cos(rotation) / scale
ss = tf.sin(rotation) / scale
cx = (sc - 1) * w * 0.5 + ss * h * 0.5
cy = -ss * w * 0.5 + (sc - 1) * h * 0.5
ze = tf.zeros_like(scale)
# Apply transformation to image
p = tf.transpose([sc, ss, -cx - tx, -ss, sc, -cy - ty, ze, ze])
image_shape = image.shape
image = tf.contrib.image.transform(image, p, interpolation="BILINEAR")
image.set_shape(image_shape)
# Apply transformation to landmarks
a_r = tf.linalg.inv(tf.transpose([[sc, -ss], [ss, sc]]))
a_t = tf.expand_dims(tf.transpose([cx + tx, cy + ty]), -2)
landmark = tf.matmul(landmark + a_t, a_r, transpose_b=True)
return image, landmark