本文整理汇总了Python中tensorflow.python.framework.tensor_shape.scalar方法的典型用法代码示例。如果您正苦于以下问题:Python tensor_shape.scalar方法的具体用法?Python tensor_shape.scalar怎么用?Python tensor_shape.scalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.framework.tensor_shape
的用法示例。
在下文中一共展示了tensor_shape.scalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_evaluation_step
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def add_evaluation_step(result_tensor, ground_truth_tensor):
"""Inserts the operations we need to evaluate the accuracy of our results.
Args:
result_tensor: The new final node that produces results.
ground_truth_tensor: The node we feed ground truth data
into.
Returns:
Tuple of (evaluation step, prediction).
"""
with tf.name_scope('accuracy'):
with tf.name_scope('correct_prediction'):
prediction = tf.argmax(result_tensor, 1)
correct_prediction = tf.equal(
prediction, tf.argmax(ground_truth_tensor, 1))
with tf.name_scope('accuracy'):
evaluation_step = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
tf.summary.scalar('accuracy', evaluation_step)
return evaluation_step, prediction
示例2: __init__
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def __init__(self, table_ref, default_value, initializer):
"""Construct a table object from a table reference.
If requires a table initializer object (subclass of `TableInitializerBase`).
It provides the table key and value types, as well as the op to initialize
the table. The caller is responsible to execute the initialization op.
Args:
table_ref: The table reference, i.e. the output of the lookup table ops.
default_value: The value to use if a key is missing in the table.
initializer: The table initializer to use.
"""
super(InitializableLookupTableBase,
self).__init__(initializer.key_dtype, initializer.value_dtype,
table_ref.op.name.split("/")[-1])
self._table_ref = table_ref
self._default_value = ops.convert_to_tensor(
default_value, dtype=self._value_dtype)
self._default_value.get_shape().merge_with(tensor_shape.scalar())
self._init = initializer.initialize(self)
示例3: __init__
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def __init__(self, iterator_resource, initializer, output_types,
output_shapes):
"""Creates a new iterator from the given iterator resource.
NOTE(mrry): Most users will not call this initializer directly, and will
instead use `Iterator.from_dataset()` or `Dataset.make_one_shot_iterator()`.
Args:
iterator_resource: A `tf.resource` scalar `tf.Tensor` representing the
iterator.
initializer: A `tf.Operation` that should be run to initialize this
iterator.
output_types: A nested structure of `tf.DType` objects corresponding to
each component of an element of this iterator.
output_shapes: A nested structure of `tf.TensorShape` objects
corresponding to each component of an element of this dataset.
"""
self._iterator_resource = iterator_resource
self._initializer = initializer
self._output_types = output_types
self._output_shapes = output_shapes
示例4: enumerate
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def enumerate(self, start=0):
"""Enumerate the elements of this dataset. Similar to python's `enumerate`.
For example:
```python
# NOTE: The following examples use `{ ... }` to represent the
# contents of a dataset.
a = { 1, 2, 3 }
b = { (7, 8), (9, 10), (11, 12) }
# The nested structure of the `datasets` argument determines the
# structure of elements in the resulting dataset.
a.enumerate(start=5) == { (5, 1), (6, 2), (7, 3) }
b.enumerate() == { (0, (7, 8)), (1, (9, 10)), (2, (11, 12)) }
Args:
start: A `tf.int64` scalar `tf.Tensor`, representing the start
value for enumeration.
Returns:
A `Dataset`.
"""
max_value = np.iinfo(dtypes.int64.as_numpy_dtype).max
return Dataset.zip((Dataset.range(start, max_value), self))
示例5: map
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def map(self, map_func, num_threads=None, output_buffer_size=None):
"""Maps `map_func` across this datset.
Args:
map_func: A function mapping a nested structure of tensors (having
shapes and types defined by `self.output_shapes` and
`self.output_types`) to another nested structure of tensors.
num_threads: (Optional.) A `tf.int32` scalar `tf.Tensor`, representing
the number of threads to use for processing elements in parallel. If
not specified, elements will be processed sequentially without
buffering.
output_buffer_size: (Optional.) A `tf.int64` scalar `tf.Tensor`,
representing the maximum number of processed elements that will be
buffered when processing in parallel.
Returns:
A `Dataset`.
"""
return MapDataset(self, map_func, num_threads, output_buffer_size)
示例6: _padding_value_to_tensor
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def _padding_value_to_tensor(value, output_type):
"""Converts the padding value to a tensor.
Args:
value: The padding value.
output_type: Its expected dtype.
Returns:
A scalar `Tensor`.
Raises:
ValueError: if the padding value is not a scalar.
TypeError: if the padding value's type does not match `output_type`.
"""
value = ops.convert_to_tensor(value, name="padding_value")
if not value.shape.is_compatible_with(tensor_shape.scalar()):
raise ValueError(
"Padding value should be a scalar, but is not: %s" % value)
if value.dtype != output_type:
raise TypeError(
"Padding value tensor (%s) does not match output type: %s"
% (value, output_type))
return value
示例7: __init__
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def __init__(self, table_ref, default_value, initializer):
"""Construct a table object from a table reference.
If requires a table initializer object (subclass of `TableInitializerBase`).
It provides the table key and value types, as well as the op to initialize
the table. The caller is responsible to execute the initialization op.
Args:
table_ref: The table reference, i.e. the output of the lookup table ops.
default_value: The value to use if a key is missing in the table.
initializer: The table initializer to use.
"""
super(InitializableLookupTableBase, self).__init__(
initializer.key_dtype, initializer.value_dtype,
table_ref.op.name.split("/")[-1])
self._table_ref = table_ref
self._default_value = ops.convert_to_tensor(default_value,
dtype=self._value_dtype)
self._default_value.get_shape().merge_with(tensor_shape.scalar())
self._init = initializer.initialize(self)
示例8: variable_summaries
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def variable_summaries(var):
"""Attach a lot of summaries to a Tensor (for TensorBoard visualization)."""
with tf.name_scope('summaries'):
mean = tf.reduce_mean(var)
tf.summary.scalar('mean', mean)
with tf.name_scope('stddev'):
stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
tf.summary.scalar('stddev', stddev)
tf.summary.scalar('max', tf.reduce_max(var))
tf.summary.scalar('min', tf.reduce_min(var))
tf.summary.histogram('histogram', var)
示例9: _event_shape
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def _event_shape(self):
return tensor_shape.scalar()
示例10: size
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def size(self, name=None):
"""Compute the number of elements in this table.
Args:
name: A name for the operation (optional).
Returns:
A scalar tensor containing the number of elements in this table.
"""
with ops.name_scope(name, "%s_Size" % self._name,
[self._table_ref]) as scope:
# pylint: disable=protected-access
return gen_lookup_ops._lookup_table_size_v2(self._table_ref, name=scope)
# pylint: enable=protected-access
示例11: scalar_shape
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def scalar_shape(unused_op):
"""Shape function for ops that output a scalar value."""
return [tensor_shape.scalar()]
示例12: make_dataset_resource
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def make_dataset_resource(self):
"""Creates a `tf.Tensor` of `tf.resource` tensor representing this dataset.
Returns:
A scalar `tf.Tensor` of `tf.resource` type, which represents this dataset.
"""
raise NotImplementedError("Dataset.make_dataset_resource")
示例13: repeat
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def repeat(self, count=None):
"""Repeats this dataset `count` times.
Args:
count: (Optional.) A `tf.int64` scalar `tf.Tensor`, representing the
number of times the elements of this dataset should be repeated. The
default behavior (if `count` is `None` or `-1`) is for the elements to
be repeated indefinitely.
Returns:
A `Dataset`.
"""
return RepeatDataset(self, count)
示例14: take
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def take(self, count):
"""Creates a `Dataset` with at most `count` elements from this dataset.
Args:
count: A `tf.int64` scalar `tf.Tensor`, representing the number of
elements of this dataset that should be taken to form the new dataset.
If `count` is -1, or if `count` is greater than the size of this
dataset, the new dataset will contain all elements of this dataset.
Returns:
A `Dataset`.
"""
return TakeDataset(self, count)
示例15: skip
# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import scalar [as 别名]
def skip(self, count):
"""Creates a `Dataset` that skips `count` elements from this dataset.
Args:
count: A `tf.int64` scalar `tf.Tensor`, representing the number
of elements of this dataset that should be skipped to form the
new dataset. If `count` is greater than the size of this
dataset, the new dataset will contain no elements. If `count`
is -1, skips the entire dataset.
Returns:
A `Dataset`.
"""
return SkipDataset(self, count)