Try to understand interssection over union from scratch

Hi all,

I am trying to understand yolo v1 using pytorch from scratch. I have seen several codes how to code iou (interssection over union). In kaggle i found an example I try to understand it, here is the link:

My questions are:
What mean the three dots … founded in box1_x1 = boxes_preds[…, 0:1]

And can we write this instruction differently? Because I can’t find any examples in python or pytorch that contain three dots.

Many thanks in advance for your help.

This is a python constant.

https://docs.python.org/library/constants.html#Ellipsis

You can even print this constant

# Try this
print(...)
# Output
# Ellipsis

You can use this for indexing, as way of saying “I don´t care”, thus accepting stuff with different dimensions.

In pytorch it would be the same when you put -1 in view, for example.

tensor = torch.rand(1, 2, 3, 4, 5)
print(tensor.view(-1, 2, 3, 4, 5).shape)
print(tensor.view(-1, 3, 4, 5).shape)
print(tensor.view(-1, 4, 5).shape)
print(tensor.view(-1, 5).shape)
print(tensor.view(-1).shape)
# Output
# torch.Size([1, 2, 3, 4, 5])
# torch.Size([2, 3, 4, 5])
# torch.Size([6, 4, 5])
# torch.Size([24, 5])
# torch.Size([120])

Here are some examples to get yourself familiar with this.

But this is a useful and robust way to accept stuff with many different dimensions and address the thing that you actually want.

Hope this helps :smile:

1 Like

Hi @Matias_Vasquez,

Thanks a lot for the explanation and for the examples. :slightly_smiling_face:

Now I understand it very well.

1 Like