ImageAI icon indicating copy to clipboard operation
ImageAI copied to clipboard

correct_yolo_boxes

Open plenari opened this issue 6 years ago • 5 comments

Detetion.custom.init.CustomDetectionUtils.correct_yolo_boxes

@staticmethod
def correct_yolo_boxes(boxes, image_h, image_w, net_h, net_w):
    
    new_w, new_h = net_w, net_h
    for i in range(len(boxes)):
        x_offset, x_scale = (net_w - new_w) / 2. / net_w, float(new_w) / net_w
        y_offset, y_scale = (net_h - new_h) / 2. / net_h, float(new_h) / net_h
        boxes[i].xmin = int((boxes[i].xmin - x_offset) / x_scale * image_w)
        boxes[i].xmax = int((boxes[i].xmax - x_offset) / x_scale * image_w)
        boxes[i].ymin = int((boxes[i].ymin - y_offset) / y_scale * image_h)
        boxes[i].ymax = int((boxes[i].ymax - y_offset) / y_scale * image_h)

hello, I'm confused. Isn't net_w equal to new_w here, so x_sacle is always equal to 1? In my opinion, when using kmeans to generate anchors boxes, you can directly zoom the image to 416*416. Can you also directly zoom back anchors boxes according to the size of the original image? So I don't know how x_offset works? Thanks very much?

plenari avatar Sep 15 '19 15:09 plenari

good point. Also x_offset is a little redundant on its definition.

It is a bit different from the original implementation

It may be related to #338 looks lie another bug introduced while taking this implementation to ImageAI, maybe @OlafenwaMoses can help us to understand this

rola93 avatar Sep 16 '19 15:09 rola93

the following message was originally posted on #353 but the issue was closed as the main point on the issue was solved. However the message contain some clues to the current #352 issue, which wasn't solved yet

I found that init.CustomObjectDetection.detectObjectsFromImage operation uses init.CustomDetectionUtils.correct_yolo_boxes line 1270 but the init.DetectionModelTrainer.evaluateModel calls the utils.evaluate operation here which also calls the correct_yolo_boxes from the util module: those both implementations on current ImageAI version are different, but they are exactly the same in the original implementation.

Up to this point, my guess is that maybe, the implementation on init.CustomDetectionUtils.correct_yolo_boxes was sligthly modified to use square images, assuming/forcing them to be square before calling it, but it was not adjusted in the evaluate method.

rola93 avatar Sep 19 '19 13:09 rola93

any news on this @OlafenwaMoses @plenari ?

rola93 avatar Oct 11 '19 15:10 rola93

@rola93 , hi, did you ever figure out how to get around this?

SB2020-eye avatar Jun 14 '21 12:06 SB2020-eye

saddle, nope. However, someone closed the issu, and in addition to this, there is a new ImageAI version, so need to check if it is still there. May be @OlafenwaMoses has some news on this.

rola93 avatar Jun 14 '21 13:06 rola93