pytorch-yolo-v3 icon indicating copy to clipboard operation
pytorch-yolo-v3 copied to clipboard

Runtimeerror

Open qsc232344 opened this issue 5 years ago • 4 comments

File "detect.py", line 234, in output = torch.cat((output,prediction)) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 8 and 86 in dimension 1 at C:\w\1\s\windows\pytorch\aten\src\TH/generic/THTensor.cpp:689 How can I debug that? Thx

qsc232344 avatar Dec 05 '19 06:12 qsc232344

The scripts continues if i modifly the line 230 of detect.py to :

        if not write:
            output = prediction
            write = 1
        else:
            output = prediction
            output = torch.cat((output,prediction))

but only the last detected image is boxed, i think that if the images are individually "detected", then all will have boxes

barresoft avatar Jan 09 '20 14:01 barresoft

This problem may occured due to line146 in util.py(https://github.com/ayooshkathuria/pytorch-yolo-v3/blob/fbb4ef98d5a598f4c8eded6d618a599b7d289e2f/util.py#L146), 'img_pred_.size(0)' may become 0 when filtered by 'non_zero_ind'. Therefore, I solve this problem by add the code behind line146 as below: if not image_pred_.size(0): output = 0 continue and insert a part of code before line215 in detect.py(https://github.com/ayooshkathuria/pytorch-yolo-v3/blob/fbb4ef98d5a598f4c8eded6d618a599b7d289e2f/detect.py#L215): for im_num, image in enumerate(imlist[i * batch_size: min((i + 1) * batch_size, len(imlist))]): end = time.time() im_id = i * batch_size + im_num print("{0:20s} predicted in {1:6.3f} seconds".format(image.split("/")[-1], (end - start) / batch_size)) print("{0:20s} {1:s}".format("Object Detected:", 'None')) print("----------------------------------------------------------") this is for the compatible print out. Hope this can help u, best wishes!

chrisway613 avatar Apr 04 '20 11:04 chrisway613

great!it fix the problem!

pppaulpeter avatar Jun 09 '21 16:06 pppaulpeter

The scripts continues if i modifly the line 230 of detect.py to :

        if not write:
            output = prediction
            write = 1
        else:
            output = prediction
            output = torch.cat((output,prediction))

but only the last detected image is boxed, i think that if the images are individually "detected", then all will have boxes

if output.size()[1] == prediction.size()[1]: output = torch.cat((output,prediction)) The remaining codes are consistent

siyuhe0120 avatar Aug 04 '21 02:08 siyuhe0120