WongKinYiu / ScaledYOLOv4

Scaled-YOLOv4: Scaling Cross Stage Partial Network
GNU General Public License v3.0
2.02k stars 572 forks source link

RuntimeError: input and output sizes should be greater than 0, but got input (H: 20, W: 20) output (H: 0, W: 0) #185

Open MyoungHaSong opened 3 years ago

MyoungHaSong commented 3 years ago

First of all, thank you for sharing your code.

The following error occurred while running the test in the csp version.

I run this code.

python test.py --img 640 --conf 0.001 --batch 8 --device 0 --data coco.yaml --cfg models/yolov4-csp.cfg --weights weights/yolov4-csp.weights

python test.py --img 640 --conf 0.001 --batch 8 --device 0 --data coco.yaml --cfg models/yolov4-csp.cfg --weights weights/yolov4-csp.weights Namespace(augment=False, batch_size=8, cfg='models/yolov4-csp.cfg', conf_thres=0.001, data='./data/coco.yaml', device='0', img_size=640, iou_thres=0.65, merge=False, names='data/coco.names', save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['weights/yolov4-csp.weights'])

Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX TITAN X', total_memory=12211MB)

Traceback (most recent call last): File "test.py", line 299, in opt.verbose) File "test.py", line 91, in test _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 577, in call result = self.forward(*input, *kwargs) File "/yolo/models/models.py", line 293, in forward return self.forward_once(x) File "/yolo/models/models.py", line 347, in forward_once x = module(x) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 577, in call result = self.forward(input, **kwargs) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/upsampling.py", line 131, in forward return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners) File "/opt/conda/lib/python3.6/site-packages/torch/nn/functional.py", line 3143, in interpolate return torch._C._nn.upsample_nearest2d(input, output_size, sfl[0], sfl[1]) RuntimeError: input and output sizes should be greater than 0, but got input (H: 20, W: 20) output (H: 0, W: 0)

WongKinYiu commented 3 years ago

try to set half=False.

MyoungHaSong commented 3 years ago

@WongKinYiu I made the settings as you said,

    try:
        ckpt = torch.load(weights[0], map_location=device)  # load checkpoint
        ckpt['model'] = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()}
        model.load_state_dict(ckpt['model'], strict=False)
    except:
        load_darknet_weights(model, weights[0])
    imgsz = check_img_size(imgsz, s=32)  # check img_size

# Half
#half = device.type != 'cpu'  # half precision only supported on CUDA
half = False
if half:
    model.half()

# Configure
model.eval()
with open(data) as f:
    data = yaml.load(f, Loader=yaml.FullLoader)  # model dict
nc = 1 if single_cls else int(data['nc'])  # number of classes

but I get the following error.

File "test.py", line 300, in opt.verbose) File "test.py", line 92, in test _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 577, in call result = self.forward(*input, *kwargs) File "/yolo/models/models.py", line 293, in forward return self.forward_once(x) File "/yolo/models/models.py", line 347, in forward_once x = module(x) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 577, in call result = self.forward(input, **kwargs) File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/upsampling.py", line 131, in forward return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners) File "/opt/conda/lib/python3.6/site-packages/torch/nn/functional.py", line 3143, in interpolate return torch._C._nn.upsample_nearest2d(input, output_size, sfl[0], sfl[1]) RuntimeError: input and output sizes should be greater than 0, but got input (H: 20, W: 20) output (H: 0, W: 0)

Kid-Kisuke commented 2 years ago

try code from this commit https://github.com/WongKinYiu/ScaledYOLOv4/tree/4dfcec67f8b7db4893ed66000dd1b317691373a4