本文整理汇总了Python中tensorflow.compat.v2.int64方法的典型用法代码示例。如果您正苦于以下问题:Python v2.int64方法的具体用法?Python v2.int64怎么用?Python v2.int64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.compat.v2
的用法示例。
在下文中一共展示了v2.int64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict(
{
"images": {
"clean": tfds.features.Tensor(
shape=[224, 224, 3], dtype=tf.uint8
),
"adversarial": tfds.features.Tensor(
shape=[224, 224, 3], dtype=tf.uint8
),
},
"label": tfds.features.Tensor(shape=(), dtype=tf.int64),
}
),
supervised_keys=("images", "label"),
)
示例2: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict(
{
"speech": tfds.features.Audio(),
"text": tfds.features.Text(
encoder_config=self.builder_config.text_encoder_config
),
"speaker_id": tf.int64,
"chapter_id": tf.int64,
"id": tf.string,
"label": tfds.features.ClassLabel(names=_LABELS),
}
),
supervised_keys=("speech", "label"),
homepage=_URL,
citation=_CITATION,
metadata=tfds.core.MetadataDict(sample_rate=16000,),
)
示例3: _key2seed
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _key2seed(a):
"""Converts an RNG key to an RNG seed.
Args:
a: an RNG key, an ndarray of shape [] and dtype `np.int64`.
Returns:
an RNG seed, a tensor of shape [2] and dtype `tf.int32`.
"""
def int64_to_int32s(a):
"""Converts an int64 tensor of shape [] to an int32 tensor of shape [2]."""
a = tf.cast(a, tf.uint64)
fst = tf.cast(a, tf.uint32)
snd = tf.cast(
tf.bitwise.right_shift(a, tf.constant(32, tf.uint64)), tf.uint32)
a = [fst, snd]
a = tf.nest.map_structure(lambda x: tf.cast(x, tf.int32), a)
a = tf.stack(a)
return a
return int64_to_int32s(a.data)
示例4: _seed2key
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _seed2key(a):
"""Converts an RNG seed to an RNG key.
Args:
a: an RNG seed, a tensor of shape [2] and dtype `tf.int32`.
Returns:
an RNG key, an ndarray of shape [] and dtype `np.int64`.
"""
def int32s_to_int64(a):
"""Converts an int32 tensor of shape [2] to an int64 tensor of shape []."""
a = tf.bitwise.bitwise_or(
tf.cast(a[0], tf.uint64),
tf.bitwise.left_shift(
tf.cast(a[1], tf.uint64), tf.constant(32, tf.uint64)))
a = tf.cast(a, tf.int64)
return a
return tf_np.asarray(int32s_to_int64(a))
示例5: true_divide
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def true_divide(x1, x2):
def _avoid_float64(x1, x2):
if x1.dtype == x2.dtype and x1.dtype in (tf.int32, tf.int64):
x1 = tf.cast(x1, dtype=tf.float32)
x2 = tf.cast(x2, dtype=tf.float32)
return x1, x2
def f(x1, x2):
if x1.dtype == tf.bool:
assert x2.dtype == tf.bool
float_ = dtypes.default_float_type()
x1 = tf.cast(x1, float_)
x2 = tf.cast(x2, float_)
if not dtypes.is_allow_float64():
# tf.math.truediv in Python3 produces float64 when both inputs are int32
# or int64. We want to avoid that when is_allow_float64() is False.
x1, x2 = _avoid_float64(x1, x2)
return tf.math.truediv(x1, x2)
return _bin_op(f, x1, x2)
示例6: _testBinOp
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _testBinOp(self, a, b, out, f, types=None):
a = t2a(tf.convert_to_tensor(value=a, dtype=np.int32))
b = t2a(tf.convert_to_tensor(value=b, dtype=np.int32))
if not isinstance(out, arrays.ndarray):
out = t2a(tf.convert_to_tensor(value=out, dtype=np.int32))
if types is None:
types = [[np.int32, np.int32, np.int32],
[np.int64, np.int32, np.int64],
[np.int32, np.int64, np.int64],
[np.float32, np.int32, np.float64],
[np.int32, np.float32, np.float64],
[np.float32, np.float32, np.float32],
[np.float64, np.float32, np.float64],
[np.float32, np.float64, np.float64]]
for a_type, b_type, out_type in types:
o = f(a.astype(a_type), b.astype(b_type))
self.assertIs(o.dtype.type, out_type)
self.assertAllEqual(out.astype(out_type), o)
示例7: testCumProdAndSum
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def testCumProdAndSum(self):
def run_test(arr, *args, **kwargs):
for fn in self.array_transforms:
arg = fn(arr)
self.match(
array_ops.cumprod(arg, *args, **kwargs),
np.cumprod(arg, *args, **kwargs))
self.match(
array_ops.cumsum(arg, *args, **kwargs),
np.cumsum(arg, *args, **kwargs))
run_test([])
run_test([1, 2, 3])
run_test([1, 2, 3], dtype=float)
run_test([1, 2, 3], dtype=np.float32)
run_test([1, 2, 3], dtype=np.float64)
run_test([1., 2., 3.])
run_test([1., 2., 3.], dtype=int)
run_test([1., 2., 3.], dtype=np.int32)
run_test([1., 2., 3.], dtype=np.int64)
run_test([[1, 2], [3, 4]], axis=1)
run_test([[1, 2], [3, 4]], axis=0)
run_test([[1, 2], [3, 4]], axis=-1)
run_test([[1, 2], [3, 4]], axis=-2)
示例8: setUp
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def setUp(self):
super(LogicTest, self).setUp()
self.array_transforms = [
lambda x: x, # Identity,
tf.convert_to_tensor,
np.array,
lambda x: np.array(x, dtype=np.int32),
lambda x: np.array(x, dtype=np.int64),
lambda x: np.array(x, dtype=np.float32),
lambda x: np.array(x, dtype=np.float64),
array_ops.array,
lambda x: array_ops.array(x, dtype=tf.int32),
lambda x: array_ops.array(x, dtype=tf.int64),
lambda x: array_ops.array(x, dtype=tf.float32),
lambda x: array_ops.array(x, dtype=tf.float64),
]
示例9: testOutputIsPermutation
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def testOutputIsPermutation(self):
"""Checks that stateless_random_shuffle outputs a permutation."""
for dtype in (tf.int32, tf.int64, tf.float32, tf.float64):
identity_permutation = tf.range(10, dtype=dtype)
random_shuffle_seed_1 = tff_rnd.stateless_random_shuffle(
identity_permutation, seed=tf.constant((1, 42), tf.int64))
random_shuffle_seed_2 = tff_rnd.stateless_random_shuffle(
identity_permutation, seed=tf.constant((2, 42), tf.int64))
# Check that the shuffles are of the correct dtype
for shuffle in (random_shuffle_seed_1, random_shuffle_seed_2):
np.testing.assert_equal(shuffle.dtype, dtype.as_numpy_dtype)
random_shuffle_seed_1 = self.evaluate(random_shuffle_seed_1)
random_shuffle_seed_2 = self.evaluate(random_shuffle_seed_2)
identity_permutation = self.evaluate(identity_permutation)
# Check that the shuffles are different
self.assertTrue(
np.abs(random_shuffle_seed_1 - random_shuffle_seed_2).max())
# Check that the shuffles are indeed permutations
for shuffle in (random_shuffle_seed_1, random_shuffle_seed_2):
self.assertAllEqual(set(shuffle), set(identity_permutation))
示例10: testOutputIsIndependentOfInputValues
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def testOutputIsIndependentOfInputValues(self):
"""stateless_random_shuffle output is independent of input_tensor values."""
# Generate sorted array of random numbers to control that the result
# is independent of `input_tesnor` values
np.random.seed(25)
random_input = np.random.normal(size=[10])
random_input.sort()
for dtype in (tf.int32, tf.int64, tf.float32, tf.float64):
# Permutation of a sequence [0, 1, .., 9]
random_permutation = tff_rnd.stateless_random_shuffle(
tf.range(10, dtype=dtype), seed=(100, 42))
random_permutation = self.evaluate(random_permutation)
# Shuffle `random_input` with the same seed
random_shuffle_control = tff_rnd.stateless_random_shuffle(
random_input, seed=(100, 42))
random_shuffle_control = self.evaluate(random_shuffle_control)
# Checks that the generated permutation does not depend on the underlying
# values
np.testing.assert_array_equal(
np.argsort(random_permutation), np.argsort(random_shuffle_control))
示例11: testOutputIsStatelessSession
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def testOutputIsStatelessSession(self):
"""Checks that stateless_random_shuffle is stateless across Sessions."""
random_permutation_next_call = None
for dtype in (tf.int32, tf.int64, tf.float32, tf.float64):
random_permutation = tff_rnd.stateless_random_shuffle(
tf.range(10, dtype=dtype), seed=tf.constant((100, 42), tf.int64))
with tf.compat.v1.Session() as sess:
random_permutation_first_call = sess.run(random_permutation)
if random_permutation_next_call is not None:
# Checks that the values are the same across different dtypes
np.testing.assert_array_equal(random_permutation_first_call,
random_permutation_next_call)
with tf.compat.v1.Session() as sess:
random_permutation_next_call = sess.run(random_permutation)
np.testing.assert_array_equal(random_permutation_first_call,
random_permutation_next_call)
示例12: testMultiDimensionalShape
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def testMultiDimensionalShape(self):
"""Check that stateless_random_shuffle works with multi-dim shapes."""
for dtype in (tf.int32, tf.int64, tf.float32, tf.float64):
input_permutation = tf.constant([[[1], [2], [3]], [[4], [5], [6]]],
dtype=dtype)
random_shuffle = tff_rnd.stateless_random_shuffle(
input_permutation, seed=(1, 42))
random_permutation_first_call = self.evaluate(random_shuffle)
random_permutation_next_call = self.evaluate(random_shuffle)
input_permutation = self.evaluate(input_permutation)
# Check that the dtype is correct
np.testing.assert_equal(random_permutation_first_call.dtype,
dtype.as_numpy_dtype)
# Check that the shuffles are the same
np.testing.assert_array_equal(random_permutation_first_call,
random_permutation_next_call)
# Check that the output shape is correct
np.testing.assert_equal(random_permutation_first_call.shape,
input_permutation.shape)
示例13: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
"image":
tfds.features.Image(shape=(105, 105, 3), encoding_format="png"),
"alphabet":
tfds.features.ClassLabel(num_classes=_NUM_ALPHABETS),
"alphabet_char_id":
tf.int64,
"label":
tfds.features.ClassLabel(num_classes=_NUM_CLASSES),
}),
supervised_keys=("image", "label"),
homepage=_BASE_URL,
citation=_CITATION,
)
示例14: _parse_single_image
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _parse_single_image(self, example_proto):
"""Parses single video from the input tfrecords.
Args:
example_proto: tfExample proto with a single video.
Returns:
dict with all frames, positions and actions.
"""
feature_map = {
"image": tf.io.FixedLenFeature(shape=[], dtype=tf.string),
"filename": tf.io.FixedLenFeature(shape=[], dtype=tf.string),
"label": tf.io.FixedLenFeature(shape=[], dtype=tf.int64),
}
parse_single = tf.io.parse_single_example(example_proto, feature_map)
return parse_single
示例15: _info
# 需要导入模块: from tensorflow.compat import v2 [as 别名]
# 或者: from tensorflow.compat.v2 import int64 [as 别名]
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description="Dataset with images from 5 classes (see config name for "
"information on the specific class)",
features=tfds.features.FeaturesDict({
"image": tfds.features.Image(),
"image/filename": tfds.features.Text(),
"PetID": tfds.features.Text(),
"attributes": {name: tf.int64 for name in _INT_FEATS},
"label": tfds.features.ClassLabel(num_classes=5),
}),
supervised_keys=("attributes", "label"),
homepage="https://www.kaggle.com/c/petfinder-adoption-prediction/data",
citation=_CITATION,
)