Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

What problem does `batch` solve in Tensorflow Dataset pipeline creation and how does it interact with the (mini-) batch size used in training?

When building input pipelines with Tensorflow's Dataset API, batching comes up a lot. For example in: tf.data: Build TensorFlow input pipelines or Output differences when changing order of batch(), shuffle() and repeat().

What I've not been able to get a good answer on, though, is what problem batching in dataset generation solves in the first place or why I should use it. Can someone enlighten me?

I presume the dataset batches are an optimization to maximize throughput to a GPU, given limited memory, especially if the whole dataset doesn't fit into memory. Are there other scenarios?

I have a somewhat better idea of the purpose of the batch_size parameter in the fit function, from, e.g. What is a batch in TensorFlow? However, what is the interaction or relationship between the dataset batches and the batch_size specified in the fit function for training.

How should either be chosen?

question from:https://stackoverflow.com/questions/65836846/what-problem-does-batch-solve-in-tensorflow-dataset-pipeline-creation-and-how

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have an answer for the second question, how the batches in the dataset and the batch_size parameter in the fit function interact. Per the documentation of fit:

Do not specify the batch_size if your data is in the form of datasets, generators, or keras.utils.Sequence instances (since they generate batches).

So the fit function will take the batches straight from the input pipeline. Specify one or the other but not both. Specifying the batch size in the input pipeline, presumably permits optimizations upstream. This makes it also a partial answer to the first question. Still, I'm curious if someone has a better explanation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...