本文整理匯總了Python中tensorflow.python.ops.standard_ops.to_int64方法的典型用法代碼示例。如果您正苦於以下問題:Python standard_ops.to_int64方法的具體用法?Python standard_ops.to_int64怎麽用?Python standard_ops.to_int64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.ops.standard_ops
的用法示例。
在下文中一共展示了standard_ops.to_int64方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: one_hot_encoding
# 需要導入模塊: from tensorflow.python.ops import standard_ops [as 別名]
# 或者: from tensorflow.python.ops.standard_ops import to_int64 [as 別名]
def one_hot_encoding(labels,
num_classes,
on_value=1.0,
off_value=0.0,
outputs_collections=None,
scope=None):
"""Transform numeric labels into onehot_labels using `tf.one_hot`.
Args:
labels: [batch_size] target labels.
num_classes: Total number of classes.
on_value: A scalar defining the on-value.
off_value: A scalar defining the off-value.
outputs_collections: Collection to add the outputs.
scope: Optional scope for name_scope.
Returns:
One-hot encoding of the labels.
"""
with ops.name_scope(scope, 'OneHotEncoding', [labels, num_classes]) as sc:
labels = ops.convert_to_tensor(labels)
if labels.dtype == dtypes.int32:
labels = standard_ops.to_int64(labels)
outputs = standard_ops.one_hot(
labels, num_classes, on_value=on_value, off_value=off_value)
return utils.collect_named_outputs(outputs_collections, sc, outputs)
示例2: one_hot_encoding
# 需要導入模塊: from tensorflow.python.ops import standard_ops [as 別名]
# 或者: from tensorflow.python.ops.standard_ops import to_int64 [as 別名]
def one_hot_encoding(labels,
num_classes,
on_value=1.0,
off_value=0.0,
outputs_collections=None,
scope=None):
"""Transform numeric labels into onehot_labels using `tf.one_hot`.
Args:
labels: [batch_size] target labels.
num_classes: Total number of classes.
on_value: A scalar defining the on-value.
off_value: A scalar defining the off-value.
outputs_collections: Collection to add the outputs.
scope: Optional scope for name_scope.
Returns:
One-hot encoding of the labels.
"""
with ops.name_scope(scope, 'OneHotEncoding', [labels, num_classes]) as sc:
labels = ops.convert_to_tensor(labels)
if labels.dtype == dtypes.int32:
labels = standard_ops.to_int64(labels)
outputs = standard_ops.one_hot(labels,
num_classes,
on_value=on_value,
off_value=off_value)
return utils.collect_named_outputs(outputs_collections, sc, outputs)
示例3: one_hot_encoding
# 需要導入模塊: from tensorflow.python.ops import standard_ops [as 別名]
# 或者: from tensorflow.python.ops.standard_ops import to_int64 [as 別名]
def one_hot_encoding(labels,
num_classes,
on_value=1.0,
off_value=0.0,
outputs_collections=None,
scope=None):
"""Transform numeric labels into onehot_labels using `tf.one_hot`.
Args:
labels: [batch_size] target labels.
num_classes: total number of classes.
on_value: A scalar defining the on-value.
off_value: A scalar defining the off-value.
outputs_collections: collection to add the outputs.
scope: Optional scope for name_scope.
Returns:
one hot encoding of the labels.
"""
with ops.name_scope(scope, 'OneHotEncoding', [labels, num_classes]) as sc:
labels = ops.convert_to_tensor(labels)
if labels.dtype == dtypes.int32:
labels = standard_ops.to_int64(labels)
outputs = standard_ops.one_hot(labels,
num_classes,
on_value=on_value,
off_value=off_value)
return utils.collect_named_outputs(outputs_collections, sc, outputs)
示例4: one_hot_encoding
# 需要導入模塊: from tensorflow.python.ops import standard_ops [as 別名]
# 或者: from tensorflow.python.ops.standard_ops import to_int64 [as 別名]
def one_hot_encoding(target, n_classes, on_value=1.0, off_value=0.0,
name="OneHotEncoding"):
""" One Hot Encoding.
Transform numeric labels into a binary vector.
Input:
The Labels Placeholder.
Output:
2-D Tensor, The encoded labels.
Arguments:
target: `Placeholder`. The labels placeholder.
n_classes: `int`. Total number of classes.
on_value: `scalar`. A scalar defining the on-value.
off_value: `scalar`. A scalar defining the off-value.
name: A name for this layer (optional). Default: 'OneHotEncoding'.
"""
with tf.name_scope(name):
if target.dtype != dtypes.int64:
target = standard_ops.to_int64(target)
target = standard_ops.one_hot(target, n_classes,
on_value=on_value,
off_value=off_value)
# Track output tensor.
tf.add_to_collection(tf.GraphKeys.LAYER_TENSOR + '/' + name, target)
return target