2
$\begingroup$

I am using YOLO v. 4 to perform object detection and classification on a large number of images. I do this through the Python interface. My images are all sorts of sizes and aspect ratios.
Examples of using Darknet / YOLO from the command line such as in this Colab notebook simply throw images at the darknet executable without any apparent considaration for image size or aspect ratio. This makes me think YOLO does some scaling/cropping/insertion of blank parts automatically.
Then when I look at the darknet_images Python module that comes with the Darknet/YOLO framework, the approach seems to be to use cv2 to scale images to the size of the network prior to detection in YOLO. In particular, this seems to generally skew the aspect ratio. Now I am confused: should I scale or not prior to detection via darknet.detect_image()?
I can create image objects with darknet.make_image() using the image's native size and feed them to darknet.detect_image() without any complaints, so what does Darknet do about the size in that case?
I am also wondering if it would be better to scale a, say 1000x500 image to my Darknet network's size of 608x608 as a 608x304 image in a 608x608 "frame", leaving the remainder of the frame blank (white or black)? Or should I flat out scale the 1000x500 image to 608x608, distorting the aspect ratio heavily? I suppose YOLO's training takes some amount of distortion into account via data augmentation, but I guess there must be limits to how much distortion it can tolerate?

$\endgroup$

1 Answer 1

1
$\begingroup$

I seem to have figured it out now. When using darknet.detect_image, it calls predict_image which in turn is network_predict_image. The latter resizes the image if it is not already the same size as the network's input layer.

If you instead call darknet detector test from the command line, as I have seen examples do as mentioned in my original question, the "chain of command" goes through test_detector which resizes the image if it is not already the size of the network's input layer.

So, in any case it seems that images get resized to fit the network's input layer along the way and I do not have to do anything in particular to handle it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.