YOLOv3 中的批处理和细分 [英] batch and subdivisions in YOLOv3
问题描述
我正在使用 AlexeyAB 的暗网分支的 YOLOv3 和 YOLOv3-Tiny.我知道图像大小必须是 32 的倍数.batch
除以 subdivisions
决定了将并行处理的图像数量.
I'm using YOLOv3 and YOLOv3-Tiny from AlexeyAB's fork of Darknet. I understand that the image size must be a multiple of 32. And that batch
divided by subdivisions
determines the number of images that will be processed in parallel.
比如默认的yolov3.cfg文件中batch size为64
,细分为16
,表示一次加载4张图片,取其中的 16 个小批次完成一次迭代.
For example, the batch size in the default yolov3.cfg file is 64
, and subdivision is 16
, meaning 4 images will be loaded at once, and it will take 16 of these mini batches to complete one iteration.
我没有看到的内容 在维基中:
这些值有限制吗?它们是否需要是 16 的倍数?2的幂?我可以有 batch=25
和 subdivisions=5
吗?
Are there restrictions on these values? Do they need to be a multiple of 16? Power of 2? Can I have batch=25
and subdivisions=5
?
推荐答案
我相信不是必须是 2 的幂,重要的是 batch
必须可以被 subdivisions
因为代码使用小批量的 batch/subdivisions
,如您在 parcer.c 中所见:
I believe it is not a must to be a power of 2, the important thing is that batch
must be divisible by subdivisions
as the code uses small batches of batch / subdivisions
as you can see in parcer.c:
net->batch/= subdivs;
然后在每个步骤中处理的图像数量定义为detector.c:
then the number of images processed in every step is defines as in detector.c:
int imgs = net.batch * net.subdivisions * ngpus;
虽然dark_cuda.h中定义的BLOCK
是512,但是内核中使用的num_blocks
不必被2整除正如在 dark_cuda.c 中所见:
Although the defined BLOCK
in dark_cuda.h is 512, the used num_blocks
in the kernels doesn't have to be divisible by 2 as can be seen in dark_cuda.c:
int get_number_of_blocks(int array_size, int block_size)
{
return array_size / block_size + ((array_size % block_size > 0) ? 1 : 0);
}
我认为唯一的问题可能是性能问题,因为 CUDA 以 32 为一组运行,因此任何不是 2 的倍数的数字都可能导致部分已用内存未得到充分利用.
I think the only problem could be a performance issue as CUDA runs in wraps of 32, so any number not a multiple of 2 may cause part of the used memory to not be fully utilized.
但是,我建议您尝试使用这些参数训练您的网络,以确认它按预期工作.
However, I recommend that you try training your network with these parameters to confirm that it works as desired.
这篇关于YOLOv3 中的批处理和细分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!