本文整理汇总了Python中tensorflow.python.framework.dtypes.DType方法的典型用法代码示例。如果您正苦于以下问题:Python dtypes.DType方法的具体用法?Python dtypes.DType怎么用?Python dtypes.DType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.framework.dtypes
的用法示例。
在下文中一共展示了dtypes.DType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parameterInfo
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def parameterInfo(self,
shape: Tuple[int, ...] = (1,),
latentShape: Tuple[int, ...] = ()) -> ParameterInfo:
"""Initializers of the parameters of the distribution.
Draw random initialization values for each parameter matching the
provided `shape`, `lantentShape`, and `dtype`. This method has to
be implemented by concrete distributions to provide reasonable
random initalizations used during `Distribution.random`.
Arguments:
shape: `Tuple[int, ...]` the shape of the distribution.
latentShape: `Tuple[int, ...]` the latent shape of the
distribution.
dtype: `DType` the data type of the distribution.
Returns:
`Dict[str, Tensor]` map from parameter names to `Tensor` s
containing the random initial values for the parameters.
"""
...
示例2: __init__
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [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
示例3: __init__
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def __init__(self,
name: str = "NA",
dtype: tf.DType = tf.float32,
drawType: DrawType = DrawType.SAMPLE,
updateType: UpdateType = UpdateType.ALL,
persistent: bool = True) -> None:
self.__name = name
self.__dtype = dtype
self.__drawType = drawType
self.__updateType = updateType
self.__persistent = persistent
示例4: dtype
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def dtype(self) -> DType:
"""The dtype of the distribution."""
return(self.__dtype)
示例5: __init__
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def __init__(self, *input_types, **kwargs):
"""Create a `Defun` decorator.
Args:
*input_types: A list of `tf.DType`
**kwargs: Optional keyword arguments, including
func_name - (optional). A python string, the name to use to
declare this `Function` in the graph.
grad_func - (optional). A function implementing the gradient
of the function-to-register. This is either a
`_DefinedFunction` or a `Declare` object. The gradient
function must satisify the criterion defined in
function.proto:GradientDef.
python_grad_func - (optional). A function implementing the
gradient of the function python-side. This function must
take the current op and the gradients w.r.t. its outputs,
and return the gradients w.r.t. the inputs. That is it must
implement the interface expected by `tf.RegisterGradient`).
This will be called by tf.gradients to add the gradient ops
to the graph. At most one of grad_func and python_grad_func
can be specified.
out_names = (optional). A list of strings, one per output
tensor.
shape_func - (optional). A function taking the op and returning a list
of static shapes to set for the function's outputs.
"""
self._input_types = input_types
self._func_name = kwargs.pop("func_name", None)
self._grad_func = kwargs.pop("grad_func", None)
self._python_grad_func = kwargs.pop("python_grad_func", None)
self._out_names = kwargs.pop("out_names", None)
self._extra_kwargs = kwargs
示例6: output_types
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def output_types(self):
"""Returns the type of each component of an element of this iterator.
Returns:
A nested structure of `tf.DType` objects corresponding to each component
of an element of this iterator.
"""
return self._output_types
示例7: instantiate
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def instantiate(self, input_types):
"""Instantiate this function given input argument types.
Args:
input_types: A list of data types for the inputs.
Returns:
_DefinedFunction for the given input types.
"""
# Stringify the type list.
key = _type_list_to_str(input_types)
defined = self._overload.get(key)
if not defined:
# If not defined yet, define the function given the input types.
name = self._func_name
if name is not None:
name = "_".join([name, key])
defined = _DefinedFunction(self._func, self._argnames, input_types, name,
None, self._python_grad_func,
out_names=self._out_names,
**self._extra_kwargs)
_ = defined.name # Fully instantiate the function definition.
if self._grad_func:
# If _grad_func is given, it is another
# _OverloadedFunction. We need to instantiate it with the
# right input types.
output_types = [
dtypes.DType(_.type)
for _ in defined.definition.signature.output_arg
]
# pylint: disable=protected-access
defined._grad_func = self._grad_func.instantiate(input_types +
output_types)
# pylint: enable=protected-access
self._overload[key] = defined
return defined
示例8: __init__
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def __init__(self, *input_types, **kwargs):
"""Create a `Defun` decorator.
Args:
*input_types: A list of `tf.DType`
**kwargs: Optional keyword arguments, including
func_name - (optional). A python string, the name to use to
declare this `Function` in the graph.
grad_func - (optional). A function implementing the gradient
of the function-to-register. This is either a
`_DefinedFunction` or a `Declare` object. The gradient
function must satisify the criterion defined in
function.proto:GradientDef.
python_grad_func - (optional). A function implementing the
gradient of the function python-side. This function must
take the current op and the gradients w.r.t. its outputs,
and return the gradients w.r.t. the inputs. That is it must
implement the interface expected by `tf.RegisterGradient`).
This will be called by tf.gradients to add the gradient ops
to the graph. At most one of grad_func and python_grad_func
can be specified.
out_names = (optional). A list of strings, one per output
tensor.
"""
self._input_types = input_types
self._func_name = kwargs.pop("func_name", None)
self._grad_func = kwargs.pop("grad_func", None)
self._python_grad_func = kwargs.pop("python_grad_func", None)
self._out_names = kwargs.pop("out_names", None)
self._extra_kwargs = kwargs
示例9: instantiate
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def instantiate(self, input_types):
"""Instantiate this function given input argument types.
Args:
input_types: A list of data types for the inputs.
Returns:
_DefinedFunction for the given input types.
"""
# Stringify the type list.
key = _type_list_to_str(input_types)
defined = self._overload.get(key)
if not defined:
# If not defined yet, define the function given the input types.
name = self._func_name
if name is not None:
name = "_".join([name, key])
defined = _DefinedFunction(self._func, self._argnames, input_types, name,
None, self._python_grad_func,
**self._extra_kwargs)
_ = defined.name # Fully instantiate the function definition.
if self._grad_func:
# If _grad_func is given, it is another
# _OverloadedFunction. We need to instantiate it with the
# right input types.
output_types = [
dtypes.DType(_.type)
for _ in defined.definition.signature.output_arg
]
# pylint: disable=protected-access
defined._grad_func = self._grad_func.instantiate(input_types +
output_types)
# pylint: enable=protected-access
self._overload[key] = defined
return defined
示例10: __init__
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def __init__(self, *input_types, **kwargs):
"""Create a `Defun` decorator.
Args:
*input_types: A list of `tf.DType`
**kwargs: Optional keyword arguments, including
func_name - (optional). A python string, the name to use to
declare this `Function` in the graph.
grad_func - (optional). A function implementing the gradient
of the function-to-register. This is either a
`_DefinedFunction` or a `Declare` object. The gradient
function must satisify the criterion defined in
function.proto:GradientDef.
python_grad_func - (optional). A function implementing the
gradient of the function python-side. This function must
take the current op and the gradients w.r.t. its outputs,
and return the gradients w.r.t. the inputs. That is it must
implement the interface expected by `tf.RegisterGradient`).
This will be called by tf.gradients to add the gradient ops
to the graph. At most one of grad_func and python_grad_func
can be specified.
"""
self._input_types = input_types
self._func_name = kwargs.pop("func_name", None)
self._grad_func = kwargs.pop("grad_func", None)
self._python_grad_func = kwargs.pop("python_grad_func", None)
self._extra_kwargs = kwargs
示例11: make_tf_graph
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def make_tf_graph(input_types):
"""
Decorator to help construct TensorFlow 1.x model.
Parameters
----------
input_types: list of tuple
List of input types. E.g. [(3, 224, 224, tf.int32)] represent 1 input,
with shape (3, 224, 224), and the expected data type is tf.int32. The
dtype is optional, in case it's missing, tf.float32 will be used.
Returns
-------
tf.Graph, list of str, list of str
"""
def wrapper(ops):
with tf.Graph().as_default() as model:
inputs = []
for input_type in input_types:
input_type = tuple(input_type)
if len(input_type) > 0 and isinstance(input_type[-1], dtypes.DType):
shape, dtype = input_type[:-1], input_type[-1]
else:
shape, dtype = input_type, tf.float32
inputs.append(tf.placeholder(shape=shape, dtype=dtype))
outputs = ops(*inputs)
return model, inputs, outputs
return wrapper
示例12: _get_types_from_tensor_info_dict
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def _get_types_from_tensor_info_dict(tensor_info_dict):
"""Returns a map of keys to DType objects.
Args:
tensor_info_dict: map with TensorInfo proto as values.
Returns:
Map with corresponding DType objects as values.
"""
return {
key: dtypes.DType(tensor_info.dtype)
for key, tensor_info in tensor_info_dict.items()
}
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:15,代码来源:signature_def_utils_impl.py
示例13: get_signature_def_input_types
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def get_signature_def_input_types(signature):
"""Returns map of output names to their types.
Args:
signature: SignatureDef proto.
Returns:
Map from string to DType objects.
"""
return _get_types_from_tensor_info_dict(signature.inputs)
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:12,代码来源:signature_def_utils_impl.py
示例14: get_signature_def_output_types
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def get_signature_def_output_types(signature):
"""Returns map of output names to their types.
Args:
signature: SignatureDef proto.
Returns:
Map from string to DType objects.
"""
return _get_types_from_tensor_info_dict(signature.outputs)
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:12,代码来源:signature_def_utils_impl.py
示例15: get_variable_to_dtype_map
# 需要导入模块: from tensorflow.python.framework import dtypes [as 别名]
# 或者: from tensorflow.python.framework.dtypes import DType [as 别名]
def get_variable_to_dtype_map(self):
from tensorflow.python.framework import dtypes
return {name: dtypes.DType(type_enum)
for name, type_enum in self._GetVariableToDataTypeMap().items()}
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:6,代码来源:pywrap_tensorflow_internal.py