How to input a list of lists with different sizes in tf.data.Dataset

前端 未结 4 1420
一整个雨季
一整个雨季 2020-12-03 01:49

I have a long list of lists of integers (representing sentences, each one of different sizes) that I want to feed using the tf.data library. Each list (of the lists of list)

4条回答
  •  日久生厌
    2020-12-03 02:03

    In addition to @mrry's answer, the following code is also possible if you would like to create (images, labels) pair:

    import itertools
    data = tf.data.Dataset.from_generator(lambda: itertools.izip_longest(images, labels),
                                          output_types=(tf.float32, tf.float32),
                                          output_shapes=(tf.TensorShape([None, None, 3]), 
                                                         tf.TensorShape([None])))
    
    iterator = dataset.make_one_shot_iterator()
    next_element = iterator.get_next()
    
    with tf.Session() as sess:
        image, label = sess.run(next_element)  # ==> shape: [320, 420, 3], [20]
        image, label = sess.run(next_element)  # ==> shape: [1280, 720, 3], [40]
    

提交回复
热议问题