tensorflow - Regarding the use of tf.train.shuffle_batch() to create batches -


in tensorflow tutorial, gives following example regarding tf.train.shuffle_batch():

# creates batches of 32 images , 32 labels. image_batch, label_batch = tf.train.shuffle_batch(      [single_image, single_label],      batch_size=32,      num_threads=4,      capacity=50000,      min_after_dequeue=10000) 

i not clear meaning of capacity , min_after_dequeue. in example, set 50000 , 10000 respectively. logic kind of setup, or mean. if input has 200 images , 200 labels, happen?

the tf.train.shuffle_batch() function uses tf.randomshufflequeue internally accumulate batches of batch_size elements, sampled uniformly @ random elements in queue.

many training algorithms, such stochastic gradient descent–based algorithms tensorflow uses optimize neural networks, rely on sampling records uniformly @ random entire training set. however, not practical load entire training set in memory (in order sample it), tf.train.shuffle_batch() offers compromise: fills internal buffer between min_after_dequeue , capacity elements, , samples uniformly @ random buffer. many training processes, improves accuracy of model , provides adequate randomization.

the min_after_dequeue , capacity arguments have indirect effect on training performance. setting large min_after_dequeue value delay start of training, because tensorflow has process @ least many elements before training can start. capacity upper bound on amount of memory input pipeline consume: setting large may cause training process run out of memory (and possibly start swapping, impair training throughput).

if dataset has 200 images, possible load entire dataset in memory. tf.train.shuffle_batch() quite inefficient, because enqueue each image , label multiple times in tf.randomshufflequeue. in case, may find more efficient following instead, using tf.train.slice_input_producer() , tf.train.batch():

random_image, random_label = tf.train.slice_input_producer([all_images, all_labels],                                                            shuffle=true)  image_batch, label_batch = tf.train.batch([random_image, random_label],                                           batch_size=32) 

Comments