-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resizing : keeping aspect ratio, or not #232
Comments
Hi, In the OpenCV version of Yolo you can keep aspect ratio right now, just replace this code:
to this:
|
There are at least 3 versions of Yolo:
No. Yolo v1 used fully conected layers, file This my fork fully corresponds to the Yolo v2 that uses
So now with keeping of aspect ratio we can get about 48.1 mAP (COCO) so it adds about +4.1 mAP for COCO: https://pjreddie.com/darknet/yolo/
May be I will update it latter. Maybe soon Joseph will release a new version of Yolo with new improvements, and I'll add it all together. This version of Yolo v2 works a bit worse with different aspects of the training and detection datasets, but it works. Aspect ratio invariance is achieved by using crop that depends on Line 697 in 5a2efd5
|
Thank you once again for your completer answer. If I'm modifying your code to include the keeping of the aspect ratio, would you be interested in a Pull Request? |
For OpenCV, looking at the definition of blobFromImage, it appears to me that the behaviour is different to kept aspect ratio in pjreddie Darknet:
It seems to resize and cut the parts of the image that aren't fitting in a square, instead of adding black margins (letterbox) |
Yes, you are right, But there are trade-off in any cases - below is an example of resizing an image in different ways:
Known Yolo problem is a difficult to detect of small objects. And So yes, I'll apply your pull request, but I think there should be an if-branch that depends on command line flag, which allows us to use the current For example: |
Hi AlexeyAB , |
Update your code from GitHub. To use letterbox:
|
Thanks for your reply.
|
Shall I use a varied aspect ratio for training or not? finally, I have to do inference on a constant aspect ratio.and in the .cfg file what should be the width and height? if my training images are of size 150(width)x80(height) to 600(width)x200(height). I am using YOLOV4 |
I know it's the old issue, but i think this issue is very important. You said the resize method keeping aspect ratio improved model's performance. But, it seems that your preprocessing method is based on the resize method not keeping aspect ratio. Are there any reason for that? |
On MSCOCO |
@AlexeyAB |
Hi,
In your implementation of Darknet, when resizing the image, the aspect ratio of the image is not kept in the function get_image_from_stream_resize:
darknet/src/image.c
Line 627 in 5a2efd5
used instead of the original resizing function letterbox_image_into in the pjreddie version:
darknet/src/image.c
Line 892 in 5a2efd5
https://github.com/pjreddie/darknet/blob/532c6e1481e78ba0e27c56f4492a7e8d3cc36597/src/image.c#L913
(in the original repo)
that was resizing the image keeping the aspect ratio and putting it in a letterbox.
It is the same in the OpenCV implementation you pushed some days ago (no kept aspect ratio)
https://github.com/opencv/opencv/blob/73af899b7c737677f008b831c8e61eaeb2984342/samples/dnn/yolo_object_detection.cpp#L60
Why this difference?
It seems to me it is the old behavior of YOLO (v1) : https://github.com/pjreddie/darknet/blame/179ed8ec76f329eb22360440c3836fdcb2560330/src/demo.c#L44
Why didn't you update this behavior in the same way?
It seems to me than not keeping the aspect ratio would mean you HAVE TO use the same aspect ratio for the training images and the test/application images/videos (and I saw you writing that at different places)
Does this mean that a network trained with one version of YOLO isn't fully usable with the other one (having the same results)?
In my case, I have several training images, but some of them are in portrait orientation, while the application video will be a landscape orientation video. Does that mean I can't use them? (Only with your implementation not keeping aspect ratio, or in any case?)
Thank you
The text was updated successfully, but these errors were encountered: