本文整理汇总了Python中tensorflow.split方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.split方法的具体用法?Python tensorflow.split怎么用?Python tensorflow.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.split方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_session
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def create_session(config_dict=dict(), force_as_default=False):
config = tf.ConfigProto()
for key, value in config_dict.items():
fields = key.split('.')
obj = config
for field in fields[:-1]:
obj = getattr(obj, field)
setattr(obj, fields[-1], value)
session = tf.Session(config=config)
if force_as_default:
session._default_session = session.as_default()
session._default_session.enforce_nesting = False
session._default_session.__enter__()
return session
#----------------------------------------------------------------------------
# Initialize all tf.Variables that have not already been initialized.
# Equivalent to the following, but more efficient and does not bloat the tf graph:
# tf.variables_initializer(tf.report_unitialized_variables()).run()
示例2: init_uninited_vars
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def init_uninited_vars(vars=None):
if vars is None: vars = tf.global_variables()
test_vars = []; test_ops = []
with tf.control_dependencies(None): # ignore surrounding control_dependencies
for var in vars:
assert is_tf_expression(var)
try:
tf.get_default_graph().get_tensor_by_name(var.name.replace(':0', '/IsVariableInitialized:0'))
except KeyError:
# Op does not exist => variable may be uninitialized.
test_vars.append(var)
with absolute_name_scope(var.name.split(':')[0]):
test_ops.append(tf.is_variable_initialized(var))
init_vars = [var for var, inited in zip(test_vars, run(test_ops)) if not inited]
run([var.initializer for var in init_vars])
#----------------------------------------------------------------------------
# Set the values of given tf.Variables.
# Equivalent to the following, but more efficient and does not bloat the tf graph:
# tfutil.run([tf.assign(var, value) for var, value in var_to_value_dict.items()]
示例3: preprocess_batch
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def preprocess_batch(images_batch, preproc_func=None):
"""
Creates a preprocessing graph for a batch given a function that processes
a single image.
:param images_batch: A tensor for an image batch.
:param preproc_func: (optional function) A function that takes in a
tensor and returns a preprocessed input.
"""
if preproc_func is None:
return images_batch
with tf.variable_scope('preprocess'):
images_list = tf.split(images_batch, int(images_batch.shape[0]))
result_list = []
for img in images_list:
reshaped_img = tf.reshape(img, img.shape[1:])
processed_img = preproc_func(reshaped_img)
result_list.append(tf.expand_dims(processed_img, axis=0))
result_images = tf.concat(result_list, axis=0)
return result_images
示例4: __call__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def __call__(self, inputs, state, scope=None):
"""GRU cell with layer normalization."""
input_dim = inputs.get_shape().as_list()[1]
num_units = self._num_units
with tf.variable_scope(scope or "gru_cell"):
with tf.variable_scope("gates"):
w_h = tf.get_variable(
"w_h", [num_units, 2 * num_units],
initializer=self._w_h_initializer())
w_x = tf.get_variable(
"w_x", [input_dim, 2 * num_units],
initializer=self._w_x_initializer(input_dim))
z_and_r = (_layer_norm(tf.matmul(state, w_h), scope="layer_norm/w_h") +
_layer_norm(tf.matmul(inputs, w_x), scope="layer_norm/w_x"))
z, r = tf.split(tf.sigmoid(z_and_r), 2, 1)
with tf.variable_scope("candidate"):
w = tf.get_variable(
"w", [input_dim, num_units], initializer=self._w_initializer)
u = tf.get_variable(
"u", [num_units, num_units], initializer=self._u_initializer)
h_hat = (r * _layer_norm(tf.matmul(state, u), scope="layer_norm/u") +
_layer_norm(tf.matmul(inputs, w), scope="layer_norm/w"))
new_h = (1 - z) * state + z * self._activation(h_hat)
return new_h, new_h
示例5: batch_random_flip
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def batch_random_flip(input_):
"""Simultaneous horizontal random flip."""
if isinstance(input_, (float, int)):
return input_
shape = input_.get_shape().as_list()
batch_size = shape[0]
height = shape[1]
width = shape[2]
channels = shape[3]
res = tf.split(axis=0, num_or_size_splits=batch_size, value=input_)
res = [elem[0, :, :, :] for elem in res]
res = [tf.image.random_flip_left_right(elem) for elem in res]
res = [tf.reshape(elem, [1, height, width, channels]) for elem in res]
res = tf.concat(axis=0, values=res)
return res
# build a one hot representation corresponding to the integer tensor
# the one-hot dimension is appended to the integer tensor shape
示例6: get_layer_size
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def get_layer_size(self, layer_name):
if layer_name == 'logits':
return self._component.num_actions
if layer_name == 'last_layer':
return self._hidden_layer_sizes[-1]
if not layer_name.startswith('layer_'):
logging.fatal(
'Invalid layer name: "%s" Can only retrieve from "logits", '
'"last_layer", and "layer_*".',
layer_name)
# NOTE(danielandor): Since get_layer_size is called before the
# model has been built, we compute the layer size directly from
# the hyperparameters rather than from self._layers.
layer_index = int(layer_name.split('_')[1])
return self._hidden_layer_sizes[layer_index]
示例7: clip_to_window
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def clip_to_window(keypoints, window, scope=None):
"""Clips keypoints to a window.
This op clips any input keypoints to a window.
Args:
keypoints: a tensor of shape [num_instances, num_keypoints, 2]
window: a tensor of shape [4] representing the [y_min, x_min, y_max, x_max]
window to which the op should clip the keypoints.
scope: name scope.
Returns:
new_keypoints: a tensor of shape [num_instances, num_keypoints, 2]
"""
with tf.name_scope(scope, 'ClipToWindow'):
y, x = tf.split(value=keypoints, num_or_size_splits=2, axis=2)
win_y_min, win_x_min, win_y_max, win_x_max = tf.unstack(window)
y = tf.maximum(tf.minimum(y, win_y_max), win_y_min)
x = tf.maximum(tf.minimum(x, win_x_max), win_x_min)
new_keypoints = tf.concat([y, x], 2)
return new_keypoints
示例8: scale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def scale(boxlist, y_scale, x_scale, scope=None):
"""scale box coordinates in x and y dimensions.
Args:
boxlist: BoxList holding N boxes
y_scale: (float) scalar tensor
x_scale: (float) scalar tensor
scope: name scope.
Returns:
boxlist: BoxList holding N boxes
"""
with tf.name_scope(scope, 'Scale'):
y_scale = tf.cast(y_scale, tf.float32)
x_scale = tf.cast(x_scale, tf.float32)
y_min, x_min, y_max, x_max = tf.split(
value=boxlist.get(), num_or_size_splits=4, axis=1)
y_min = y_scale * y_min
y_max = y_scale * y_max
x_min = x_scale * x_min
x_max = x_scale * x_max
scaled_boxlist = box_list.BoxList(
tf.concat([y_min, x_min, y_max, x_max], 1))
return _copy_extra_fields(scaled_boxlist, boxlist)
示例9: intersection
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def intersection(boxlist1, boxlist2, scope=None):
"""Compute pairwise intersection areas between boxes.
Args:
boxlist1: BoxList holding N boxes
boxlist2: BoxList holding M boxes
scope: name scope.
Returns:
a tensor with shape [N, M] representing pairwise intersections
"""
with tf.name_scope(scope, 'Intersection'):
y_min1, x_min1, y_max1, x_max1 = tf.split(
value=boxlist1.get(), num_or_size_splits=4, axis=1)
y_min2, x_min2, y_max2, x_max2 = tf.split(
value=boxlist2.get(), num_or_size_splits=4, axis=1)
all_pairs_min_ymax = tf.minimum(y_max1, tf.transpose(y_max2))
all_pairs_max_ymin = tf.maximum(y_min1, tf.transpose(y_min2))
intersect_heights = tf.maximum(0.0, all_pairs_min_ymax - all_pairs_max_ymin)
all_pairs_min_xmax = tf.minimum(x_max1, tf.transpose(x_max2))
all_pairs_max_xmin = tf.maximum(x_min1, tf.transpose(x_min2))
intersect_widths = tf.maximum(0.0, all_pairs_min_xmax - all_pairs_max_xmin)
return intersect_heights * intersect_widths
示例10: matched_intersection
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def matched_intersection(boxlist1, boxlist2, scope=None):
"""Compute intersection areas between corresponding boxes in two boxlists.
Args:
boxlist1: BoxList holding N boxes
boxlist2: BoxList holding N boxes
scope: name scope.
Returns:
a tensor with shape [N] representing pairwise intersections
"""
with tf.name_scope(scope, 'MatchedIntersection'):
y_min1, x_min1, y_max1, x_max1 = tf.split(
value=boxlist1.get(), num_or_size_splits=4, axis=1)
y_min2, x_min2, y_max2, x_max2 = tf.split(
value=boxlist2.get(), num_or_size_splits=4, axis=1)
min_ymax = tf.minimum(y_max1, y_max2)
max_ymin = tf.maximum(y_min1, y_min2)
intersect_heights = tf.maximum(0.0, min_ymax - max_ymin)
min_xmax = tf.minimum(x_max1, x_max2)
max_xmin = tf.maximum(x_min1, x_min2)
intersect_widths = tf.maximum(0.0, min_xmax - max_xmin)
return tf.reshape(intersect_heights * intersect_widths, [-1])
示例11: flip_boxes
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def flip_boxes(boxes):
"""Left-right flip the boxes.
Args:
boxes: rank 2 float32 tensor containing the bounding boxes -> [N, 4].
Boxes are in normalized form meaning their coordinates vary
between [0, 1].
Each row is in the form of [ymin, xmin, ymax, xmax].
Returns:
Flipped boxes.
"""
# Flip boxes.
ymin, xmin, ymax, xmax = tf.split(value=boxes, num_or_size_splits=4, axis=1)
flipped_xmin = tf.subtract(1.0, xmax)
flipped_xmax = tf.subtract(1.0, xmin)
flipped_boxes = tf.concat([ymin, flipped_xmin, ymax, flipped_xmax], 1)
return flipped_boxes
示例12: _CrossConv
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def _CrossConv(self, encoded_images):
"""Apply the motion kernel on the encoded_images."""
cross_conved_images = []
kernels = tf.split(axis=3, num_or_size_splits=4, value=self.kernel)
for (i, encoded_image) in enumerate(encoded_images):
with tf.variable_scope('cross_conv_%d' % i):
kernel = kernels[i]
encoded_image = tf.unstack(encoded_image, axis=0)
kernel = tf.unstack(kernel, axis=0)
assert len(encoded_image) == len(kernel)
assert len(encoded_image) == self.params['batch_size']
conved_image = []
for j in xrange(len(encoded_image)):
conved_image.append(self._CrossConvHelper(
encoded_image[j], kernel[j]))
cross_conved_images.append(tf.concat(axis=0, values=conved_image))
sys.stderr.write('cross_conved shape: %s\n' %
cross_conved_images[-1].get_shape())
return cross_conved_images
示例13: _Apply
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def _Apply(self, *args):
xtransform = self._TransformInputs(*args)
depth_axis = len(self._output_shape) - 1
if self.hidden is not None:
htransform = self._TransformHidden(self.hidden)
f, i, j, o = tf.split(
value=htransform + xtransform, num_or_size_splits=4, axis=depth_axis)
else:
f, i, j, o = tf.split(
value=xtransform, num_or_size_splits=4, axis=depth_axis)
if self.cell is not None:
self.cell = tf.sigmoid(f) * self.cell + tf.sigmoid(i) * tf.tanh(j)
else:
self.cell = tf.sigmoid(i) * tf.tanh(j)
self.hidden = tf.sigmoid(o) * tf.tanh(self.cell)
return self.hidden
示例14: call
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def call(self, inputs):
mean_and_log_std = self.model(inputs)
mean, log_std = tf.split(mean_and_log_std, num_or_size_splits=2, axis=1)
log_std = tf.clip_by_value(log_std, -20., 2.)
distribution = tfp.distributions.MultivariateNormalDiag(
loc=mean,
scale_diag=tf.exp(log_std)
)
raw_actions = distribution.sample()
if not self._reparameterize:
### Problem 1.3.A
### YOUR CODE HERE
raw_actions = tf.stop_gradient(raw_actions)
log_probs = distribution.log_prob(raw_actions)
log_probs -= self._squash_correction(raw_actions)
### Problem 2.A
### YOUR CODE HERE
self.actions = tf.tanh(raw_actions)
return self.actions, log_probs
示例15: conv
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import split [as 别名]
def conv(input, kernel, biases, k_h, k_w, c_o, s_h, s_w, padding="VALID", group=1):
'''From https://github.com/ethereon/caffe-tensorflow
'''
c_i = input.get_shape()[-1]
assert c_i%group==0
assert c_o%group==0
convolve = lambda i, k: tf.nn.conv2d(i, k, [1, s_h, s_w, 1], padding=padding)
if group==1:
conv = convolve(input, kernel)
else:
input_groups = tf.split(input, group, 3)
kernel_groups = tf.split(kernel, group, 3)
output_groups = [convolve(i, k) for i,k in zip(input_groups, kernel_groups)]
conv = tf.concat(output_groups, 3)
return tf.reshape(tf.nn.bias_add(conv, biases), [-1]+conv.get_shape().as_list()[1:])