How to load sparse data with TensorFlow?

后端 未结 5 1557
故里飘歌
故里飘歌 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:28

    First, to explain what that documentation means:

    1. For dense data usually you are doing:

      Serialized Example (from reader) -> parse_single_example -> batch queue -> use it.

    2. For sparse data you currently need to do:

      Serialized Example (from reader) -> batch queue -> parse_example -> use it.

    An example of this would be:

    reader  = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)
    batch_serialized_examples = tf.shuffle_batch([serialized_example], batch_size)
    feature_to_type = {
      'label': tf.FixedLenFeature([1], dtype=tf.int64),
      'sparse_feature': tf.VarLenFeature(dtype=tf.int64)
    }
    features = tf.parse_example(batch_serialized_examples, feature_to_type)
    

    Note, shuffle_batch takes a series of strings and returns batch of strings. label should be fixed len of rank == 1 from your example.

提交回复
热议问题