The use of meshgrid in pytorch/numpy
Below code is a snippet taken from https://blog.paperspace.com/how-to-implement-a-yolo-v3-object-detector-from-scratch-in-pytorch-part-3/, and I am confused as to what it is trying to achieve.
    grid = np.arange(grid_size)
    a,b = np.meshgrid(grid, grid)

    x_offset = torch.FloatTensor(a).view(-1,1)
    y_offset = torch.FloatTensor(b).view(-1,1)

    if CUDA:
        x_offset = x_offset.cuda()
        y_offset = y_offset.cuda()

    x_y_offset = torch.cat((x_offset, y_offset), 1).repeat(1,num_anchors).view(-1,2).unsqueeze(0)

I tried the case when grid_size = 3, and it outputed:
tensor([[0., 1.],
        [2., 0.],
        [1., 2.],
        [0., 1.],
        [2., 0.],
        [0., 0.],
        [1., 1.],
        [1., 2.],
        [2., 2.],
        [0., 1.],
        [2., 0.],
        [1., 2.],
        [0., 1.],
        [2., 0.],
        [0., 0.],
        [1., 1.],
        [1., 2.],
        [2., 2.],
        [0., 1.],
        [2., 0.],
        [1., 2.],
        [0., 1.],
        [2., 0.],
        [0., 0.],
        [1., 1.],
        [1., 2.],
        [2., 2.]])

I cannot quite see what is the pattern here. According to the description in the given link I think I should really expect something like:
tensor([[0,0],
        [0,0],
        [0,0],
        [0,1],
        [0,1],
        [0,1],
        [0,2],
        [0,2],
        ...]])


If you are expecting the second output you show, simply change
x_y_offset = (
    torch.cat((x_offset, y_offset), 1).repeat(1, num_anchors).view(-1, 2).unsqueeze(0)
)

to
x_y_offset = (
    torch.cat((y_offset, x_offset), 1).repeat(1, num_anchors).view(-1, 2).unsqueeze(0)
)

It just has to do with the ordering of the output of meshgrid.
