How many images per iteration in Detectron2
Asked Answered
P

3

8

I am new to using detectron2, just learning it.This might be a noob question, but I really need the answer. I find nothing related to number of epochs in the repository.

We know , epoch means single passing of all data through the model, and a batch means a certain subset of the whole dataset, that has the ability to impact the loss through gradient descent. In this model, (Detectron2) we have something called iteration. What does this iteration mean? Does it mean passing of one batch through the mode, or an epoch(that shouldn't be the case considering time per iteration)

My question is , how do I know the minimum number of iterations that will pass all my images to the model, at least once.

Petropavlovsk answered 25/8, 2020 at 11:39 Comment(0)
W
15

In detectron2, epoch is MAX_ITER * BATCH_SIZE / TOTAL_NUM_IMAGES

Worrell answered 27/8, 2020 at 3:30 Comment(4)
you mean every iteration passes one batch?Petropavlovsk
Yes. You got it. To understand these you can run plain_train_net.py from tools folder and print file names from the training loop.Worrell
@Sawradip, If you find my answer is useful, then click on the useful button. It will help others.Worrell
How do i pass the batch_size? Currently, my implementation is running out of memory, I'm not able to figure out whyZohara
R
8

I don't think the currently accepted answer is correct

single_iteration = cfg.SOLVER.NUM_GPUS * cfg.SOLVER.IMS_PER_BATCH

therefore, if you want to now how many iterations you need for an epoch (all images seen once), that number would be

iterations_for_one_epoch = TOTAL_NUM_IMAGES / single_iteration

So if you want to train for 20 epochs, you would set MAX_ITER as follows:

cfg.SOLVER.MAX_ITER = iterations_for_one_epoch * 20

Sources:

Detectron2 Docs (one iteration is one run_step-call, and that pulls one "datapoint" from the loader data = next(self._data_loader_iter))

MaskRCNN-benchmark Github issue explains it in a similar way

Renatarenate answered 25/4, 2021 at 7:57 Comment(2)
I think the equation is wrong because when I set IMS_PER_BATCH=2 and NUM_GPUS =8, it shell terminal shows an error message that 2/8 isn't divisible. ######################################################## single_iteration = cfg.SOLVER.NUM_GPUS * cfg.SOLVER.IMS_PER_BATCH ########################################################Waldenburg
Agreed with @yuhang.tao, cfg.SOLVER.IMS_PER_BATCH is the number of training images per iteration. If you run detectron2 on multi GPUs, the number of images per GPU is calculated accordingly. i.e. SOLVER.IMS_PER_BATCH/# of GPUs. See official definition here: github.com/facebookresearch/detectron2/blob/…Equalizer
C
-4

According to this source code, iteration in Detectron2 terminology equals epoch.
You should find optimal MAX_ITER value experimentally by selection optimal loss rate/train time ratio.

Centennial answered 25/8, 2020 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.