yolov7 icon indicating copy to clipboard operation
yolov7 copied to clipboard

How to set --img-size parameter for training set with diffrent input images size?

Open folkien opened this issue 2 years ago • 4 comments

How to set --img-size parameter for training set with diffrent input images size? I have a training set with images 640x352 and 1024x768 and 960x708 in the same directory. How to train custom YOLOv7 with this images set?

folkien avatar Jul 26 '22 20:07 folkien

I believe images are resized to what size you specify with --img-size. I don't believe the h/w ratio is changed however. Probably zero padding or trimming is used as needed.

mattroos avatar Jul 26 '22 21:07 mattroos

But I'm not certain if the ordering is height width, or width height. See #315

mattroos avatar Jul 26 '22 21:07 mattroos

So --img-size parameter during training is input size of neural network or what?

Previous, when i've used darknet repository for training, size of NN was defined in .cfg file and there were no other img-size definition. During training images where auto resized to input size of NN ( you could choose from resize, resize letterbox). @AlexeyAB @WongKinYiu

folkien avatar Jul 26 '22 22:07 folkien

Unfortunately, the first number in '--img-size' parameter is train square size and the second is test square size. If anyone what to use rectangle in training, you should change some codes in train.py and datasets.py.
For example, from imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size] # verify imgsz are gs-multiples to

imgsz = [check_img_size(x, gs) for x in opt.img_size]  # verify imgsz are gs-multiples
imgsz_test = imgsz

Eliza-and-black avatar Aug 01 '22 07:08 Eliza-and-black

@Eliza-and-black If I understand correctly, not making that edit to the code means we would end up testing on a different input size (and perhaps aspect ratio as well, due to nearest gs multiple). This could produce artificially low test metrics since the input is different from what the model sees during training. Is that a correct interpretation of your suggestion?

addisonklinke avatar Sep 22 '22 13:09 addisonklinke

Unfortunately, the first number in '--img-size' parameter is train square size and the second is test square size. If anyone what to use rectangle in training, you should change some codes in train.py and datasets.py. For example, from imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size] # verify imgsz are gs-multiples to

imgsz = [check_img_size(x, gs) for x in opt.img_size]  # verify imgsz are gs-multiples
imgsz_test = imgsz

What other code do I have to modify to make rect training work? I changed the lines you mentioned and solved the issues that came up, but i still don't get results from training.

LeDren avatar Oct 07 '22 07:10 LeDren