How to load sparse data with TensorFlow?

后端 未结 5 1427
故里飘歌
故里飘歌 2021-02-12 23:23

There is a small snippet about loading sparse data but I have no idea how to use it.

SparseTensors don\'t play well with queues. If you use SparseTensors

5条回答
  •  离开以前
    2021-02-12 23:30

    If you are passing sparse values as inputs , you need to create sparse placeholders using tf.sparse_placeholder.

    You should then convert your sparse tensors to dense tensor using tf.sparse_to_dense.

    For this you need to explicitly pass the sparse matrix's values , shape and indices while feeding the data in feed_dict and then later use tf.sparse_to_dense in the graph.

    In the graph :

    dense = tf.sparse_to_dense(
        sparse_indices=sparse_placeholder.indices,
        output_shape=sparse_placeholder.shape,
        sparse_values=sparse_placeholder.values,
    validate_indices=False)
    

    In the feed_dict:

    sparse_placeholder:tf.SparseTensorValue(indices=indices,values=sparse_values,dense_shape=sparse_shape)
    

提交回复
热议问题