3 from __future__ import absolute_import, print_function, division
5 import tensorflow as tf
8 all of these ops are derived from tenosrflow Object Detection API
10 def indices_to_dense_vector(indices,
15 """Creates dense vector with indices set to specific (the para "indices_value" ) and rest to zeros.
17 This function exists because it is unclear if it is safe to use
18 tf.sparse_to_dense(indices, [size], 1, validate_indices=False)
19 with indices which are not ordered.
20 This function accepts a dynamic size (e.g. tf.shape(tensor)[0])
23 indices: 1d Tensor with integer indices which are to be set to
25 size: scalar with size (integer) of output Tensor.
26 indices_value: values of elements specified by indices in the output vector
27 default_value: values of other elements in the output vector.
31 dense 1D Tensor of shape [size] with indices set to indices_values and the
32 rest set to default_value.
34 size = tf.to_int32(size)
35 zeros = tf.ones([size], dtype=dtype) * default_value
36 values = tf.ones_like(indices, dtype=dtype) * indices_value
38 return tf.dynamic_stitch([tf.range(size), tf.to_int32(indices)],
46 import matplotlib.pyplot as plt
49 a = np.random.rand(20, 30)
56 if __name__ == '__main__':