本文整理汇总了Python中tensorflow.contrib.data.python.ops.batching.dense_to_sparse_batch函数的典型用法代码示例。如果您正苦于以下问题:Python dense_to_sparse_batch函数的具体用法?Python dense_to_sparse_batch怎么用?Python dense_to_sparse_batch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dense_to_sparse_batch函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testDenseToSparseBatchDatasetWithUnknownShape
def testDenseToSparseBatchDatasetWithUnknownShape(self):
components = np.random.randint(5, size=(40,)).astype(np.int32)
iterator = (
dataset_ops.Dataset.from_tensor_slices(components)
.map(lambda x: array_ops.fill([x, x], x)).apply(
batching.dense_to_sparse_batch(
4, [5, None])).make_initializable_iterator())
init_op = iterator.initializer
get_next = iterator.get_next()
with self.cached_session() as sess:
sess.run(init_op)
for start in range(0, len(components), 4):
results = sess.run(get_next)
self.assertAllEqual([[i, j, z]
for i, c in enumerate(components[start:start + 4])
for j in range(c)
for z in range(c)], results.indices)
self.assertAllEqual([
c
for c in components[start:start + 4] for _ in range(c)
for _ in range(c)
], results.values)
self.assertAllEqual([
min(4,
len(components) - start), 5,
np.max(components[start:start + 4])
], results.dense_shape)
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next)
开发者ID:Jordan1237,项目名称:tensorflow,代码行数:32,代码来源:batch_dataset_op_test.py
示例2: testDenseToSparseBatchDatasetWithInvalidShape
def testDenseToSparseBatchDatasetWithInvalidShape(self):
input_tensor = array_ops.constant([[1]])
iterator = (dataset_ops.Dataset.from_tensors(input_tensor)
.apply(batching.dense_to_sparse_batch(4, [-2]))
.make_initializable_iterator())
init_op = iterator.initializer
with self.test_session() as sess:
with self.assertRaisesRegexp(errors.InvalidArgumentError,
"Dimension -2 must be >= -1"):
sess.run(init_op)
开发者ID:dyoung418,项目名称:tensorflow,代码行数:11,代码来源:batch_dataset_op_test.py
示例3: testDenseToSparseBatchDatasetShapeErrors
def testDenseToSparseBatchDatasetShapeErrors(self):
input_tensor = array_ops.placeholder(dtypes.int32)
iterator = (dataset_ops.Dataset.from_tensors(input_tensor).apply(
batching.dense_to_sparse_batch(4, [12])).make_initializable_iterator())
init_op = iterator.initializer
get_next = sparse_tensor.SparseTensor(*iterator.get_next())
with self.test_session() as sess:
# Initialize with an input tensor of incompatible rank.
sess.run(init_op, feed_dict={input_tensor: [[1]]})
with self.assertRaisesRegexp(errors.InvalidArgumentError,
"incompatible with the row shape"):
sess.run(get_next)
# Initialize with an input tensor that is larger than `row_shape`.
sess.run(init_op, feed_dict={input_tensor: range(13)})
with self.assertRaisesRegexp(errors.DataLossError,
"larger than the row shape"):
sess.run(get_next)
开发者ID:Crazyonxh,项目名称:tensorflow,代码行数:19,代码来源:batch_dataset_op_test.py
示例4: testDenseToSparseBatchDatasetWithInvalidShape
def testDenseToSparseBatchDatasetWithInvalidShape(self):
input_tensor = array_ops.constant([[1]])
with self.assertRaisesRegexp(ValueError, "Dimension -2 must be >= 0"):
dataset_ops.Dataset.from_tensors(input_tensor).apply(
batching.dense_to_sparse_batch(4, [-2])).make_initializable_iterator()
开发者ID:Jordan1237,项目名称:tensorflow,代码行数:5,代码来源:batch_dataset_op_test.py
示例5: _build_dataset_dense_to_sparse
def _build_dataset_dense_to_sparse(self, components):
return dataset_ops.Dataset.from_tensor_slices(components).map(
lambda x: array_ops.fill([x], x)).apply(
batching.dense_to_sparse_batch(4, [12]))
开发者ID:jinxin0924,项目名称:tensorflow,代码行数:4,代码来源:batch_dataset_op_test.py
示例6: dense_to_sparse_batch
def dense_to_sparse_batch(self, batch_size, row_shape):
"""Use: `Dataset.apply(tf.contrib.data.dense_to_sparse_batch(...))`."""
return self.apply(batching.dense_to_sparse_batch(batch_size, row_shape))
开发者ID:DjangoPeng,项目名称:tensorflow,代码行数:4,代码来源:dataset_ops.py
注:本文中的tensorflow.contrib.data.python.ops.batching.dense_to_sparse_batch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论