本文整理汇总了Python中tensorflow.python.util.compat.bytes_or_text_types方法的典型用法代码示例。如果您正苦于以下问题:Python compat.bytes_or_text_types方法的具体用法?Python compat.bytes_or_text_types怎么用?Python compat.bytes_or_text_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.util.compat
的用法示例。
在下文中一共展示了compat.bytes_or_text_types方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assert_proper_iterable
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def assert_proper_iterable(values):
"""Static assert that values is a "proper" iterable.
`Ops` that expect iterables of `Tensor` can call this to validate input.
Useful since `Tensor`, `ndarray`, byte/text type are all iterables themselves.
Args:
values: Object to be checked.
Raises:
TypeError: If `values` is not iterable or is one of
`Tensor`, `SparseTensor`, `np.array`, `tf.compat.bytes_or_text_types`.
"""
unintentional_iterables = (
(ops.Tensor, sparse_tensor.SparseTensor, np.ndarray)
+ compat.bytes_or_text_types
)
if isinstance(values, unintentional_iterables):
raise TypeError(
'Expected argument "values" to be a "proper" iterable. Found: %s' %
type(values))
if not hasattr(values, '__iter__'):
raise TypeError(
'Expected argument "values" to be iterable. Found: %s' % type(values))
示例2: __init__
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def __init__(self, value):
"""Creates a new Dimension with the given value."""
if value is None:
self._value = None
else:
self._value = int(value)
if (not isinstance(value, compat.bytes_or_text_types) and
self._value != value):
raise ValueError("Ambiguous dimension: %s" % value)
if self._value < 0:
raise ValueError("Dimension %d must be >= 0" % self._value)
示例3: _MakeStr
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def _MakeStr(v, arg_name):
if not isinstance(v, compat.bytes_or_text_types):
raise TypeError("Expected string for argument '%s' not %s." %
(arg_name, repr(v)))
return compat.as_bytes(v) # Convert unicode strings to bytes.
示例4: _FilterStr
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def _FilterStr(v):
if isinstance(v, (list, tuple)):
return _FirstNotNone([_FilterStr(x) for x in v])
if isinstance(v, compat.bytes_or_text_types):
return None
else:
return _NotNone(v)
示例5: __init__
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def __init__(self, value):
"""Creates a new Dimension with the given value."""
if value is None:
self._value = None
else:
self._value = int(value)
if (not isinstance(value, compat.bytes_or_text_types)
and self._value != value):
raise ValueError("Ambiguous dimension: %s" % value)
if self._value < 0:
raise ValueError("Dimension %d must be >= 0" % self._value)
示例6: _read_converted_names
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def _read_converted_names(self, target):
if isinstance(target, compat.bytes_or_text_types):
target_name = target
else:
target_name = target.name
if target_name in self._replica_dict:
return self._replica_dict[target_name]
else:
return target
示例7: _convert_feed
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def _convert_feed(self, feed_dict):
def _feed_fn(feed):
for tensor_type, _, _, feed_fn in session._REGISTERED_EXPANSIONS:
if isinstance(feed, tensor_type):
return feed_fn(feed)
raise TypeError('Feed argument %r has invalid type %r' % (feed,
type(feed)))
if feed_dict:
new_feed_dict = {}
for feed, feed_val in feed_dict.items():
if isinstance(feed, compat.bytes_or_text_types):
new_feeds = self._read_converted_names(feed)
if isinstance(new_feeds, list):
for i in range(self._num_replicas_per_worker):
new_feed_dict[new_feeds[i]] = feed_val[i]
else:
new_feed_dict[new_feeds] = feed_val
else:
for subfeed in _feed_fn(feed):
new_subfeeds = self._read_converted_names(subfeed)
if isinstance(new_subfeeds, list):
for i in range(self._num_replicas_per_worker):
new_feed_dict[new_subfeeds[i]] = feed_val[i]
else:
new_feed_dict[new_subfeeds] = feed_val
return new_feed_dict
else:
return feed_dict
示例8: make_str
# 需要导入模块: from tensorflow.python.util import compat [as 别名]
# 或者: from tensorflow.python.util.compat import bytes_or_text_types [as 别名]
def make_str(v, arg_name):
if not isinstance(v, compat.bytes_or_text_types):
raise TypeError("Expected string for argument '%s' not %s." %
(arg_name, repr(v)))
return compat.as_bytes(v) # Convert unicode strings to bytes.
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:7,代码来源:execute.py