MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / dense_to_sparse

Function dense_to_sparse

tensorflow/contrib/layers/python/layers/layers.py:1551–1572  ·  view source on GitHub ↗

Converts a dense tensor into a sparse tensor. An example use would be to convert dense labels to sparse ones so that they can be fed to the ctc_loss. Args: tensor: An `int` `Tensor` to be converted to a `Sparse`. eos_token: An integer. It is part of the target label that signifies

(tensor, eos_token=0, outputs_collections=None, scope=None)

Source from the content-addressed store, hash-verified

1549
1550@add_arg_scope
1551def dense_to_sparse(tensor, eos_token=0, outputs_collections=None, scope=None):
1552 """Converts a dense tensor into a sparse tensor.
1553
1554 An example use would be to convert dense labels to sparse ones
1555 so that they can be fed to the ctc_loss.
1556
1557 Args:
1558 tensor: An `int` `Tensor` to be converted to a `Sparse`.
1559 eos_token: An integer. It is part of the target label that signifies the
1560 end of a sentence.
1561 outputs_collections: Collection to add the outputs.
1562 scope: Optional scope for name_scope.
1563 """
1564 with variable_scope.variable_scope(scope, 'dense_to_sparse', [tensor]) as sc:
1565 tensor = ops.convert_to_tensor(tensor)
1566 indices = array_ops.where(
1567 math_ops.not_equal(tensor, constant_op.constant(eos_token,
1568 tensor.dtype)))
1569 values = array_ops.gather_nd(tensor, indices)
1570 shape = array_ops.shape(tensor, out_type=dtypes.int64)
1571 outputs = sparse_tensor.SparseTensor(indices, values, shape)
1572 return utils.collect_named_outputs(outputs_collections, sc.name, outputs)
1573
1574
1575@add_arg_scope

Callers

nothing calls this directly

Calls 5

variable_scopeMethod · 0.80
not_equalMethod · 0.80
constantMethod · 0.45
gather_ndMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected