本文整理汇总了Python中tensorflow.python.ops.math_ops._as_indexed_slices函数的典型用法代码示例。如果您正苦于以下问题:Python _as_indexed_slices函数的具体用法?Python _as_indexed_slices怎么用?Python _as_indexed_slices使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_as_indexed_slices函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testContainsIndexedSlices_PerReplica
def testContainsIndexedSlices_PerReplica(self):
t0 = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
t1 = math_ops._as_indexed_slices(
constant_op.constant([[0., 0.], [5, 6], [7., 8.]]))
per_replica = value_lib.PerReplica({"/gpu:0": t0, "/cpu:0": t1})
self.assertTrue(cross_device_utils.contains_indexed_slices(per_replica))
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:7,代码来源:cross_device_utils_test.py
示例2: testAggregateIndexedSlices
def testAggregateIndexedSlices(self):
t0 = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
t1 = math_ops._as_indexed_slices(
constant_op.constant([[0., 0.], [5, 6], [7., 8.]]))
total = constant_op.constant([[1., 2.], [5, 6], [10., 12.]])
result = cross_device_utils.aggregate_tensors_or_indexed_slices([t0, t1])
self.assertIsInstance(result, ops.IndexedSlices)
self._assert_values_equal(total, result)
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:9,代码来源:cross_device_utils_test.py
示例3: testMultipleGradients
def testMultipleGradients(self):
t0 = math_ops._as_indexed_slices(constant_op.constant(
[[1., 2.], [0, 0], [3., 4.]]))
t1 = math_ops._as_indexed_slices(constant_op.constant(
[[0., 0.], [5, 6], [7., 8.]]))
total = constant_op.constant(
[[1., 2.], [5, 6], [10., 12.]])
result = gradients_impl._AggregateIndexedSlicesGradients([t0, t1])
self._assert_indexed_slices_equal(total, result)
开发者ID:jinxin0924,项目名称:tensorflow,代码行数:9,代码来源:gradients_test.py
示例4: testContainsIndexedSlices_PerDeviceMapOutput
def testContainsIndexedSlices_PerDeviceMapOutput(self):
t0 = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
t1 = math_ops._as_indexed_slices(
constant_op.constant([[0., 0.], [5, 6], [7., 8.]]))
per_device = value_lib.PerDevice({
"/gpu:0": value_lib.MapOutput([t0]),
"/cpu:0": value_lib.MapOutput([t1])})
self.assertTrue(cross_tower_utils.contains_indexed_slices(per_device))
开发者ID:BhaskarNallani,项目名称:tensorflow,代码行数:9,代码来源:cross_tower_utils_test.py
示例5: testDivideIndexedSlices
def testDivideIndexedSlices(self):
t = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
n = 2
expected = constant_op.constant([[0.5, 1.], [0, 0], [1.5, 2.]])
result = cross_device_utils.divide_by_n_tensors_or_indexed_slices(t, n)
self.assertIsInstance(result, ops.IndexedSlices)
self._assert_values_equal(expected, result)
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:8,代码来源:cross_device_utils_test.py
示例6: testIndexedSlicesToTensor
def testIndexedSlicesToTensor(self):
with self.test_session():
np_val = np.random.rand(4, 4, 4, 4).astype(np.float32)
c = constant_op.constant(np_val)
c_sparse = math_ops._as_indexed_slices(c)
self.assertAllEqual(np_val.shape, c_sparse.dense_shape.eval())
c_dense = math_ops.mul(c_sparse, 1.0)
self.assertAllClose(np_val, c_dense.eval())
开发者ID:Ambier,项目名称:tensorflow,代码行数:8,代码来源:gradients_test.py
示例7: _make_output_composite_tensors_match
def _make_output_composite_tensors_match(true_graph, false_graph):
"""Rewrites {true,false}_graph's outputs to use the same _TensorLike classes.
Currently the only transformation implemented is turning a Tensor into an
equivalent IndexedSlices if the other branch returns an IndexedSlices.
Updates {true,false}_graph.{outputs,structured_outputs}.
Args:
true_graph: FuncGraph
false_graph: FuncGraph
Raises:
TypeError: if a pair of outputs cannot be rewritten.
"""
# Note: since this is only used for gradient graphs, we do not expect the
# outputs to be structured (e.g. nested lists), and thus do not need to use
# nest.flatten, etc.
true_outputs = list(true_graph.structured_outputs)
false_outputs = list(false_graph.structured_outputs)
assert len(true_outputs) == len(false_outputs)
for idx, (true_out, false_out) in enumerate(zip(true_outputs, false_outputs)):
if type(true_out) == type(false_out): # pylint: disable=unidiomatic-typecheck
continue
if (isinstance(true_out, ops.IndexedSlices) and
isinstance(false_out, ops.Tensor)):
with false_graph.as_default():
false_outputs[idx] = math_ops._as_indexed_slices(false_out)
elif (isinstance(true_out, ops.Tensor) and
isinstance(false_out, ops.IndexedSlices)):
with true_graph.as_default():
true_outputs[idx] = math_ops._as_indexed_slices(true_out)
else:
raise TypeError(
"Cannot reconcile tf.cond %i-th outputs:\n"
" true_fn returned: %s\n"
" false_fn returned: %s" % (idx, true_out, false_out))
true_graph.structured_outputs = true_outputs
true_graph.outputs = func_graph_module.flatten(true_outputs)
false_graph.structured_outputs = false_outputs
false_graph.outputs = func_graph_module.flatten(false_outputs)
开发者ID:terrytangyuan,项目名称:tensorflow,代码行数:42,代码来源:cond_v2.py
示例8: testInt64Indices
def testInt64Indices(self):
with self.test_session():
np_val = np.random.rand(4, 4, 4, 4).astype(np.float32)
c = constant_op.constant(np_val)
c_sparse = math_ops._as_indexed_slices(c)
c_sparse = ops.IndexedSlices(
c_sparse.values, math_ops.cast(c_sparse.indices, dtypes.int64),
c_sparse.dense_shape)
self.assertAllEqual(np_val.shape, c_sparse.dense_shape.eval())
c_dense = math_ops.mul(c_sparse, 1.0)
self.assertAllClose(np_val, c_dense.eval())
开发者ID:Ambier,项目名称:tensorflow,代码行数:11,代码来源:gradients_test.py
示例9: testCopyIndexedSlices
def testCopyIndexedSlices(self):
with ops.device("/cpu:0"):
t = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
destination = "/gpu:0"
result = cross_device_utils.copy_tensor_or_indexed_slices_to_device(
t, destination)
self.assertIsInstance(result, ops.IndexedSlices)
self._assert_values_equal(t, result)
self.assertEqual(device_util.resolve(destination),
device_util.resolve(result.device))
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:12,代码来源:cross_device_utils_test.py
示例10: testIndexedSlicesToTensorList
def testIndexedSlicesToTensorList(self):
with self.test_session():
numpy_list = []
dense_list = []
sparse_list = []
for _ in range(3):
np_val = np.random.rand(4, 4, 4, 4).astype(np.float32)
c = constant_op.constant(np_val)
c_sparse = math_ops._as_indexed_slices(c)
numpy_list.append(np_val)
dense_list.append(c)
sparse_list.append(c_sparse)
packed_dense = array_ops.pack(dense_list)
packed_sparse = array_ops.pack(sparse_list)
self.assertAllClose(packed_dense.eval(), packed_sparse.eval())
开发者ID:Ambier,项目名称:tensorflow,代码行数:15,代码来源:gradients_test.py
示例11: testContainsIndexedSlices_Tuple
def testContainsIndexedSlices_Tuple(self):
t0 = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
t1 = math_ops._as_indexed_slices(
constant_op.constant([[0., 0.], [5, 6], [7., 8.]]))
self.assertTrue(cross_device_utils.contains_indexed_slices((t0, t1)))
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:6,代码来源:cross_device_utils_test.py
示例12: testIsIndexedSlices
def testIsIndexedSlices(self):
t = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
self.assertTrue(cross_device_utils.contains_indexed_slices(t))
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:4,代码来源:cross_device_utils_test.py
示例13: testOneGradient
def testOneGradient(self):
t = math_ops._as_indexed_slices(constant_op.constant(
[[1., 2.], [0, 0], [3., 4.]]))
result = gradients_impl._AggregateIndexedSlicesGradients([t])
self._assert_indexed_slices_equal(t, result)
开发者ID:jinxin0924,项目名称:tensorflow,代码行数:5,代码来源:gradients_test.py
示例14: testContainsIndexedSlices_List
def testContainsIndexedSlices_List(self):
t0 = math_ops._as_indexed_slices(
constant_op.constant([[1., 2.], [0, 0], [3., 4.]]))
t1 = math_ops._as_indexed_slices(
constant_op.constant([[0., 0.], [5, 6], [7., 8.]]))
self.assertTrue(cross_tower_utils.contains_indexed_slices([t0, t1]))
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:6,代码来源:cross_tower_utils_test.py
注:本文中的tensorflow.python.ops.math_ops._as_indexed_slices函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论