WongKinYiu / yolor

implementation of paper - You Only Learn One Representation: Unified Network for Multiple Tasks (https://arxiv.org/abs/2105.04206)
GNU General Public License v3.0
1.98k stars 524 forks source link

image size attribut not working #53

Closed abdelhak51 closed 2 years ago

abdelhak51 commented 2 years ago

hi, when I change --img-size from 1280 to 320 for example it is not working and throws me an error which is :

Traceback (most recent call last): File "detect.py", line 187, in detect() File "detect.py", line 86, in detect pred = model(img, augment=opt.augment)[0] File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl return forward_call(*input, *kwargs) File "C:\Users\ASUS\Desktop\yoloR\yolor\models\models.py", line 543, in forward return self.forward_once(x) File "C:\Users\ASUS\Desktop\yoloR\yolor\models\models.py", line 594, in forward_once x = module(x, out) # WeightedFeatureFusion(), FeatureConcat() File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl return forward_call(input, **kwargs) File "C:\Users\ASUS\Desktop\yoloR\yolor\utils\layers.py", line 69, in forward return torch.cat([outputs[i] for i in self.layers], 1) if self.multiple else outputs[self.layers[0]] RuntimeError: torch.cat(): Sizes of tensors must match except in dimension 1. Got 15 and 16 in dimension 2 (The offending index is 1)

any solution for this problem .

WongKinYiu commented 2 years ago

input size should be 128x for p6 models.

abdelhak51 commented 2 years ago

thank you @WongKinYiu I solved the problem so I found that --img-size accepts 64 , 320 only

0chandansharma commented 2 years ago

So, this problem is coming because of Resize of test and train images

These functions are responsible for changing the size, For TESTING please change the shape according to these lines of code..............

# Image sizes
gs = 64 #int(max(model.stride))  # grid size (max stride)
imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size]
def check_img_size(img_size, s=32):
    # Verify img_size is a multiple of stride s
    new_size = make_divisible(img_size, int(s))  # ceil gs-multiple
    if new_size != img_size:
        print('WARNING: --img-size %g must be multiple of max stride %g, updating to %g' % (img_size, s, new_size))
    return new_size
def make_divisible(x, divisor):
    # Returns x evenly divisible by divisor
    return math.ceil(x / divisor) * divisor