DLS course 4 week 3 programming assignment 1 car detection IOU

For this problem I am writing an IOU function that returns the iou. I think I must be just mistyping something somewhere because I have drawn out the problem on paper and understand it backwards and forwards how to calculate the vertices and subtract for width and height, calculate areas, unions, and intersections, and then IOU.

But I am still getting a problem where I don’t get ‘0’ when the boxes intersect at the vertices only. I’ve stepped through my code using the test coordinates 1,1,2,2 and 2,2,3,3 and it should end up being xil = 2, yil = 2, xi2 =2, yi2 = 2 which leads to inter area being zero which should make my iou zero since iou is just dividing the inter area over the union.

My one note I would say is that I don’t utilize the hint that says to use max(height, 0) and max(width, 0) for inter area. I don’t understand what that means. But I just use inter inter area = inter width * inter height which should be zero times zero.

here is my area:

iou for intersecting boxes = 0.14285714285714285
iou for non-intersecting boxes = 1.0

AssertionError Traceback (most recent call last)
in
12 box2 = (5,6,7,8)
13 print("iou for non-intersecting boxes = " + str(iou(box1,box2)))
—> 14 assert iou(box1, box2) == 0, “Intersection must be 0”
15
16 ## Test case 3: boxes intersect at vertices only

AssertionError: Intersection must be 0\

any notes or helpful hints would be appreciated.

Thank you.

Update:

It is possible the error isn’t referring to test case 3 with (1,1,2,2) and (2,2,3,3) but rather the case of non intersecting boxes in which case I have the issue where the iou should also be zero but I am getting positive numbers. This is because normally I would take lets say xi2 - xi1 to get the width, but if xi1 is greater than xi2 because they dont intercept then i end up with a negative width value, pair that with a negative height value and I end up with a positive area when it had no area overlap at all!

Update 2:

I took a swing at just using that hint I wasn’t sure about max(height, 0) and it worked. Turns out it is just to take 0 as your height or width if your height or width is negative. Makes sense.

Well what values do you actually get for the coordinates of the intersection in the case you describe that should have 0 intersection? The numbers are the numbers, right? How do they end up as 1.0?

The point of the max with 0 is that the height and width difference values can be negative in the non-intersection case, right? What happens if the boxes are 1,1 to 2,2 and 3,3 to 4,4?

Sorry, our messages crossed in midair. Glad you figured it out …

1 Like