TensorFlow: does tf.train.batch automatically load the next batch when the batch has finished training?

后端 未结 2 579
别跟我提以往
别跟我提以往 2020-12-25 14:30

For instance, after I have created my operations, fed the batch data through the operation and run the operation, does tf.train.batch automatically feed in another batch of

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 15:30

    You need to call sess.run and pass the batch to it everytime when you want to load the next batch. See the code below.

    img = [0,1,2,3,4,5,6,7,8]
    lbl = [0,1,2,3,4,5,6,7,8]
    images = tf.convert_to_tensor(img)
    labels = tf.convert_to_tensor(lbl)
    input_queue = tf.train.slice_input_producer([images,labels])
    sliced_img = input_queue[0]
    sliced_lbl = input_queue[1]
    
    img_batch, lbl_batch = tf.train.batch([sliced_img,sliced_lbl], batch_size=3)
    with tf.Session() as sess:
        coord   = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)
    
        for i in range(0,3): #batch size
            image_batch,label_batch = sess.run([img_batch,lbl_batch ])
            print(image_batch, label_batch)
    
        coord.request_stop()
        coord.join(threads)
    

    the answer would be something like this:

    [4,1,8] [4,1,8]

    [2,3,7] [2,3,7]

    [2,6,8] [2,6,8]

提交回复
热议问题