本文整理汇总了Python中tensorflow.lin_space方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.lin_space方法的具体用法?Python tensorflow.lin_space怎么用?Python tensorflow.lin_space使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.lin_space方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generate_rand
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def _generate_rand(min_factor, max_factor, step_size):
"""Gets a random value.
Args:
min_factor: Minimum value.
max_factor: Maximum value.
step_size: The step size from minimum to maximum value.
Returns:
A random value selected between minimum and maximum value.
Raises:
ValueError: min_factor has unexpected value.
"""
if min_factor < 0 or min_factor > max_factor:
raise ValueError("Unexpected value of min_factor.")
if min_factor == max_factor:
return tf.to_float(min_factor)
# When step_size = 0, we sample the value uniformly from [min, max).
if step_size == 0:
return tf.random_uniform([1],
minval=min_factor,
maxval=max_factor)
# When step_size != 0, we randomly select one discrete value from [min, max].
num_steps = int((max_factor - min_factor) / step_size + 1)
scale_factors = tf.lin_space(min_factor, max_factor, num_steps)
shuffled_scale_factors = tf.random_shuffle(scale_factors)
return shuffled_scale_factors[0]
示例2: __init__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def __init__(self, cfg, schedule=None, is_training=True, reuse=False):
self.cfg = cfg
self.reuse = reuse
self.is_training = is_training
self.schedule = schedule
self.summaries = {}
self.depths = tf.lin_space(cfg.MIN_DEPTH, cfg.MAX_DEPTH, cfg.COST_VOLUME_DEPTH)
self.batch_norm_params = {
'decay': .995,
'epsilon': 1e-5,
'scale': True,
'renorm': True,
'renorm_clipping': schedule,
'trainable': self.is_training,
'is_training': self.is_training,
}
示例3: rand_warp
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def rand_warp(images, out_size, max_warp=0.5, name='rand_hom'):
num_batch = tf.shape(images)[0]
y = tf.lin_space(-1., 1., 2)
x = tf.lin_space(-1., 1., 2)
py, px = tf.meshgrid(y, x)
pts_orig = tf.tile(tf.concat([tf.reshape(px, [1, -1, 1]),
tf.reshape(py, [1, -1, 1])],
axis=-1), [num_batch, 1, 1])
x = pts_orig[:,:,0:1]
y = pts_orig[:,:,1:2]
rx1 = tf.random.uniform([num_batch, 2, 1], -1., -1.+ max_warp)
rx2 = tf.random.uniform([num_batch, 2, 1], 1.- max_warp, 1.)
rx = tf.concat([rx1, rx2], axis=1)
ry1 = tf.random.uniform([num_batch, 2, 1], -1., -1.+max_warp)
ry2 = tf.random.uniform([num_batch, 2, 1], 1.-max_warp, 1.)
ry = tf.reshape(tf.concat([ry1, ry2], axis=2), [num_batch, 4, 1])
pts_warp = tf.concat([rx, ry], axis=2)
h = estimate_hom(pts_orig, pts_warp)
return hom_warp(images, out_size, h)
示例4: get_random_scale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def get_random_scale(min_scale_factor, max_scale_factor, step_size):
"""Gets a random scale value.
Args:
min_scale_factor: Minimum scale value.
max_scale_factor: Maximum scale value.
step_size: The step size from minimum to maximum value.
Returns:
A random scale value selected between minimum and maximum value.
Raises:
ValueError: min_scale_factor has unexpected value.
"""
if min_scale_factor < 0 or min_scale_factor > max_scale_factor:
raise ValueError('Unexpected value of min_scale_factor.')
if min_scale_factor == max_scale_factor:
return tf.cast(min_scale_factor, tf.float32)
# When step_size = 0, we sample the value uniformly from [min, max).
if step_size == 0:
return tf.random_uniform([1],
minval=min_scale_factor,
maxval=max_scale_factor)
# When step_size != 0, we randomly select one discrete value from [min, max].
num_steps = int((max_scale_factor - min_scale_factor) / step_size + 1)
scale_factors = tf.lin_space(min_scale_factor, max_scale_factor, num_steps)
shuffled_scale_factors = tf.random_shuffle(scale_factors)
return shuffled_scale_factors[0]
示例5: get_random_scale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def get_random_scale(min_scale_factor, max_scale_factor, step_size):
"""Gets a random scale value.
Args:
min_scale_factor: Minimum scale value.
max_scale_factor: Maximum scale value.
step_size: The step size from minimum to maximum value.
Returns:
A random scale value selected between minimum and maximum value.
Raises:
ValueError: min_scale_factor has unexpected value.
"""
if min_scale_factor < 0 or min_scale_factor > max_scale_factor:
raise ValueError('Unexpected value of min_scale_factor.')
if min_scale_factor == max_scale_factor:
return tf.to_float(min_scale_factor)
# When step_size = 0, we sample the value uniformly from [min, max).
if step_size == 0:
return tf.random_uniform([1],
minval=min_scale_factor,
maxval=max_scale_factor)
# When step_size != 0, we randomly select one discrete value from [min, max].
num_steps = int((max_scale_factor - min_scale_factor) / step_size + 1)
scale_factors = tf.lin_space(min_scale_factor, max_scale_factor, num_steps)
shuffled_scale_factors = tf.random_shuffle(scale_factors)
return shuffled_scale_factors[0]
示例6: get_random_scale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def get_random_scale(min_scale_factor, max_scale_factor, step_size):
"""Gets a random scale value.
Args:
min_scale_factor: Minimum scale value.
max_scale_factor: Maximum scale value.
step_size: The step size from minimum to maximum value.
Returns:
A random scale value selected between minimum and maximum value.
Raises:
ValueError: min_scale_factor has unexpected value.
"""
if min_scale_factor < 0 or min_scale_factor > max_scale_factor:
raise ValueError('Unexpected value of min_scale_factor.')
if min_scale_factor == max_scale_factor:
return tf.cast(min_scale_factor, tf.float32)
# When step_size = 0, we sample the value uniformly from [min, max).
if step_size == 0:
return tf.random_uniform([1],
minval=min_scale_factor,
maxval=max_scale_factor)
# When step_size != 0, we randomly select one discrete value from [min, max].
num_steps = int((max_scale_factor - min_scale_factor) / step_size + 1)
scale_factors = tf.lin_space(min_scale_factor, max_scale_factor, num_steps)
shuffled_scale_factors = tf.random_shuffle(scale_factors)
return shuffled_scale_factors[0]
示例7: stereo_network_cat
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def stereo_network_cat(self, Ts, images, intrinsics):
"""3D Matching Network with view concatenation"""
cfg = self.cfg
depths = tf.lin_space(cfg.MIN_DEPTH, cfg.MAX_DEPTH, cfg.COST_VOLUME_DEPTH)
intrinsics = intrinsics_vec_to_matrix(intrinsics / 4.0)
with tf.variable_scope("stereo", reuse=self.reuse) as sc:
# extract 2d feature maps from images and build cost volume
fmaps = self.encoder(images)
volume = operators.backproject_cat(Ts, depths, intrinsics, fmaps)
self.spreds = []
with slim.arg_scope([slim.batch_norm], **self.batch_norm_params):
with slim.arg_scope([slim.conv3d],
weights_regularizer=slim.l2_regularizer(0.00005),
normalizer_fn=None,
activation_fn=None):
x = slim.conv3d(volume, 48, [3, 3, 3])
x = tf.add(x, conv3d(conv3d(x, 48), 48))
self.pred_logits = []
for i in range(self.cfg.HG_COUNT):
with tf.variable_scope("hg1_%d"%i):
x = hg.hourglass_3d(x, 4, 48)
self.pred_logits.append(self.stereo_head(x))
return self.soft_argmax(self.pred_logits[-1])
示例8: get_distibute_q
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def get_distibute_q(q_values, v_min, v_max, atoms, observations_ph):
probability = tf.nn.softmax(q_values)
atoms_range = tf.lin_space(v_min, v_max, atoms)
atoms_range = tf.expand_dims(atoms_range, 0) # 1*atoms
atoms_range = tf.expand_dims(atoms_range, -1) # 1*atoms*1
atoms_range = tf.tile(atoms_range, [tf.shape(observations_ph.get())[0], 1, 1])
q_t1_best = tf.matmul(probability, atoms_range)
q_t1_best = tf.squeeze(q_t1_best, -1)
return q_t1_best
示例9: get_random_scale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def get_random_scale(min_scale_factor, max_scale_factor, step_size):
"""Gets a random scale value.
Args:
min_scale_factor: Minimum scale value.
max_scale_factor: Maximum scale value.
step_size: The step size from minimum to maximum value.
Returns:
A random scale value selected between minimum and maximum value.
Raises:
ValueError: min_scale_factor has unexpected value.
"""
if min_scale_factor < 0 or min_scale_factor > max_scale_factor:
raise ValueError('Unexpected value of min_scale_factor.')
if min_scale_factor == max_scale_factor:
return tf.to_float(min_scale_factor)
# When step_size = 0, we sample the value uniformly from [min, max).
if step_size == 0:
return tf.random_uniform([1],
minval=min_scale_factor,
maxval=max_scale_factor)
# When step_size != 0, we randomly select one discrete value from
# [min, max].
num_steps = int((max_scale_factor - min_scale_factor) / step_size + 1)
scale_factors = tf.lin_space(min_scale_factor, max_scale_factor, num_steps)
shuffled_scale_factors = tf.random_shuffle(scale_factors)
return shuffled_scale_factors[0]
示例10: get_random_scale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def get_random_scale(min_scale_factor, max_scale_factor, step_size):
"""Gets a random scale value.
Args:
min_scale_factor: Minimum scale value.
max_scale_factor: Maximum scale value.
step_size: The step size from minimum to maximum value.
Returns:
A random scale value selected between minimum and maximum value.
Raises:
ValueError: min_scale_factor has unexpected value.
"""
if min_scale_factor < 0 or min_scale_factor > max_scale_factor:
raise ValueError('Unexpected value of min_scale_factor.')
if min_scale_factor == max_scale_factor:
return tf.to_float(min_scale_factor)
# When step_size = 0, we sample the value uniformly from [min, max).
if step_size == 0:
return tf.random_uniform([1],
minval=min_scale_factor,
maxval=max_scale_factor)
# When step_size != 0, we randomly select one discrete value from [min, max].
num_steps = int((max_scale_factor - min_scale_factor) / step_size + 1)
scale_factors = tf.lin_space(min_scale_factor, max_scale_factor, num_steps)
shuffled_scale_factors = tf.random_shuffle(scale_factors)
return shuffled_scale_factors[0]
示例11: __init__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def __init__(self, state, action, state_dims, action_dims, dense1_size, dense2_size, final_layer_init, num_atoms, v_min, v_max, scope='critic'):
# state - State input to pass through the network
# action - Action input for which the Z distribution should be predicted
self.state = state
self.action = action
self.state_dims = np.prod(state_dims) #Used to calculate the fan_in of the state layer (e.g. if state_dims is (3,2) fan_in should equal 6)
self.action_dims = np.prod(action_dims)
self.scope = scope
with tf.variable_scope(self.scope):
self.dense1_mul = dense(self.state, dense1_size, weight_init=tf.random_uniform_initializer((-1/tf.sqrt(tf.to_float(self.state_dims))), 1/tf.sqrt(tf.to_float(self.state_dims))),
bias_init=tf.random_uniform_initializer((-1/tf.sqrt(tf.to_float(self.state_dims))), 1/tf.sqrt(tf.to_float(self.state_dims))), scope='dense1')
self.dense1 = relu(self.dense1_mul, scope='dense1')
#Merge first dense layer with action input to get second dense layer
self.dense2a = dense(self.dense1, dense2_size, weight_init=tf.random_uniform_initializer((-1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))), 1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))),
bias_init=tf.random_uniform_initializer((-1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))), 1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))), scope='dense2a')
self.dense2b = dense(self.action, dense2_size, weight_init=tf.random_uniform_initializer((-1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))), 1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))),
bias_init=tf.random_uniform_initializer((-1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))), 1/tf.sqrt(tf.to_float(dense1_size+self.action_dims))), scope='dense2b')
self.dense2 = relu(self.dense2a + self.dense2b, scope='dense2')
self.output_logits = dense(self.dense2, num_atoms, weight_init=tf.random_uniform_initializer(-1*final_layer_init, final_layer_init),
bias_init=tf.random_uniform_initializer(-1*final_layer_init, final_layer_init), scope='output_logits')
self.output_probs = softmax(self.output_logits, scope='output_probs')
self.network_params = tf.trainable_variables(scope=self.scope)
self.bn_params = [] # No batch norm params
self.z_atoms = tf.lin_space(v_min, v_max, num_atoms)
self.Q_val = tf.reduce_sum(self.z_atoms * self.output_probs) # the Q value is the mean of the categorical output Z-distribution
self.action_grads = tf.gradients(self.output_probs, self.action, self.z_atoms) # gradient of mean of output Z-distribution wrt action input - used to train actor network, weighing the grads by z_values gives the mean across the output distribution
示例12: stereo_network_avg
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def stereo_network_avg(self, Ts, images, intrinsics, adj_list=None):
"""3D Matching Network with view pooling
Ts: collection of pose estimates correponding to images
images: rgb images
intrinsics: image intrinsics
adj_list: [n, m] matrix specifying frames co-visiblee frames
"""
cfg = self.cfg
depths = tf.lin_space(cfg.MIN_DEPTH, cfg.MAX_DEPTH, cfg.COST_VOLUME_DEPTH)
intrinsics = intrinsics_vec_to_matrix(intrinsics / 4.0)
with tf.variable_scope("stereo", reuse=self.reuse) as sc:
# extract 2d feature maps from images and build cost volume
fmaps = self.encoder(images)
volume = operators.backproject_avg(Ts, depths, intrinsics, fmaps, adj_list)
self.spreds = []
with slim.arg_scope([slim.batch_norm], **self.batch_norm_params):
with slim.arg_scope([slim.conv3d],
weights_regularizer=slim.l2_regularizer(0.00005),
normalizer_fn=None,
activation_fn=None):
dim = tf.shape(volume)
volume = tf.reshape(volume, [dim[0]*dim[1], dim[2], dim[3], dim[4], 64])
x = slim.conv3d(volume, 32, [1, 1, 1])
tf.add_to_collection("checkpoints", x)
# multi-view convolution
x = tf.add(x, conv3d(conv3d(x, 32), 32))
x = tf.reshape(x, [dim[0], dim[1], dim[2], dim[3], dim[4], 32])
x = tf.reduce_mean(x, axis=1)
tf.add_to_collection("checkpoints", x)
self.pred_logits = []
for i in range(self.cfg.HG_COUNT):
with tf.variable_scope("hg1_%d"%i):
x = hg.hourglass_3d(x, 4, 32)
self.pred_logits.append(self.stereo_head(x))
return self.soft_argmax(self.pred_logits[-1])
示例13: get_homographies_inv_depth
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def get_homographies_inv_depth(left_cam, right_cam, depth_num, depth_start, depth_end):
with tf.name_scope('get_homographies'):
# cameras (K, R, t)
R_left = tf.slice(left_cam, [0, 0, 0, 0], [-1, 1, 3, 3])
R_right = tf.slice(right_cam, [0, 0, 0, 0], [-1, 1, 3, 3])
t_left = tf.slice(left_cam, [0, 0, 0, 3], [-1, 1, 3, 1])
t_right = tf.slice(right_cam, [0, 0, 0, 3], [-1, 1, 3, 1])
K_left = tf.slice(left_cam, [0, 1, 0, 0], [-1, 1, 3, 3])
K_right = tf.slice(right_cam, [0, 1, 0, 0], [-1, 1, 3, 3])
# depth
depth_num = tf.reshape(tf.cast(depth_num, 'int32'), [])
inv_depth_start = tf.reshape(tf.div(1.0, depth_start), [])
inv_depth_end = tf.reshape(tf.div(1.0, depth_end), [])
inv_depth = tf.lin_space(inv_depth_start, inv_depth_end, depth_num)
depth = tf.div(1.0, inv_depth)
# preparation
num_depth = tf.shape(depth)[0]
K_left_inv = tf.matrix_inverse(tf.squeeze(K_left, axis=1))
R_left_trans = tf.transpose(tf.squeeze(R_left, axis=1), perm=[0, 2, 1])
R_right_trans = tf.transpose(tf.squeeze(R_right, axis=1), perm=[0, 2, 1])
fronto_direction = tf.slice(tf.squeeze(R_left, axis=1), [0, 2, 0], [-1, 1, 3]) # (B, D, 1, 3)
c_left = -tf.matmul(R_left_trans, tf.squeeze(t_left, axis=1))
c_right = -tf.matmul(R_right_trans, tf.squeeze(t_right, axis=1)) # (B, D, 3, 1)
c_relative = tf.subtract(c_right, c_left)
# compute
batch_size = tf.shape(R_left)[0]
temp_vec = tf.matmul(c_relative, fronto_direction)
depth_mat = tf.tile(tf.reshape(depth, [batch_size, num_depth, 1, 1]), [1, 1, 3, 3])
temp_vec = tf.tile(tf.expand_dims(temp_vec, axis=1), [1, num_depth, 1, 1])
middle_mat0 = tf.eye(3, batch_shape=[batch_size, num_depth]) - temp_vec / depth_mat
middle_mat1 = tf.tile(tf.expand_dims(tf.matmul(R_left_trans, K_left_inv), axis=1), [1, num_depth, 1, 1])
middle_mat2 = tf.matmul(middle_mat0, middle_mat1)
homographies = tf.matmul(tf.tile(K_right, [1, num_depth, 1, 1])
, tf.matmul(tf.tile(R_right, [1, num_depth, 1, 1])
, middle_mat2))
return homographies
示例14: _buckets
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import lin_space [as 别名]
def _buckets(data, bucket_count=None):
"""Create a TensorFlow op to group data into histogram buckets.
Arguments:
data: A `Tensor` of any shape. Must be castable to `float64`.
bucket_count: Optional positive `int` or scalar `int32` `Tensor`.
Returns:
A `Tensor` of shape `[k, 3]` and type `float64`. The `i`th row is
a triple `[left_edge, right_edge, count]` for a single bucket.
The value of `k` is either `bucket_count` or `1` or `0`.
"""
if bucket_count is None:
bucket_count = DEFAULT_BUCKET_COUNT
with tf.name_scope('buckets', values=[data, bucket_count]), \
tf.control_dependencies([tf.assert_scalar(bucket_count),
tf.assert_type(bucket_count, tf.int32)]):
data = tf.reshape(data, shape=[-1]) # flatten
data = tf.cast(data, tf.float64)
is_empty = tf.equal(tf.size(data), 0)
def when_empty():
return tf.constant([], shape=(0, 3), dtype=tf.float64)
def when_nonempty():
min_ = tf.reduce_min(data)
max_ = tf.reduce_max(data)
range_ = max_ - min_
is_singular = tf.equal(range_, 0)
def when_nonsingular():
bucket_width = range_ / tf.cast(bucket_count, tf.float64)
offsets = data - min_
bucket_indices = tf.cast(tf.floor(offsets / bucket_width),
dtype=tf.int32)
clamped_indices = tf.minimum(bucket_indices, bucket_count - 1)
one_hots = tf.one_hot(clamped_indices, depth=bucket_count)
bucket_counts = tf.cast(tf.reduce_sum(one_hots, axis=0),
dtype=tf.float64)
edges = tf.lin_space(min_, max_, bucket_count + 1)
left_edges = edges[:-1]
right_edges = edges[1:]
return tf.transpose(tf.stack(
[left_edges, right_edges, bucket_counts]))
def when_singular():
center = min_
bucket_starts = tf.stack([center - 0.5])
bucket_ends = tf.stack([center + 0.5])
bucket_counts = tf.stack([tf.cast(tf.size(data), tf.float64)])
return tf.transpose(
tf.stack([bucket_starts, bucket_ends, bucket_counts]))
return tf.cond(is_singular, when_singular, when_nonsingular)
return tf.cond(is_empty, when_empty, when_nonempty)
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:57,代码来源:summary.py