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

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0.

Open apiszcz opened this issue 6 years ago • 15 comments

I am not sure how this path is specified there are no folders C:\a\w.....

C:\test\yv3pytak\imgs\messi.jpg predicted in  0.047 seconds
Objects Detected:    person person person sports ball

C:\test\yv3pytak\imgs\person.jpg predicted in  0.047 seconds
Objects Detected:    person dog horse

Traceback (most recent call last):
  File "detect.py", line 234, in <module>
    output = torch.cat((output,prediction))
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 86 and 8 in dimension 1 at c:\a\w\1\s\tmp_conda_3.7_061434\conda\conda-bld\pytorch_1544163540495\work\aten\src\thc\generic/THCTensorMath.cu:83

apiszcz avatar Feb 02 '19 18:02 apiszcz

i got the same error.

156aasdfg avatar Feb 15 '19 13:02 156aasdfg

Same error here

take2rohit avatar Feb 19 '19 08:02 take2rohit

I fixed this problem in a ugly solution. The error was always reporting when detecting the image named "scream.jpg". Specifically, the right dimension returned from function "write_results" was [N, 8], however, the wrong dimension was [N, 86]. In addition, the result returned from function "write_results" contained many strange values, e.g. 6.9610e-45, -1.3956e+23, etc. Therefore, I add the following codes end the function "write_results":

output[(output > 0) & (output < 0.00001)] = 0
output[output < -10000] = 0
output[output > 10000] = 0
if len(torch.nonzero(output)) < 1:
    return torch.zeros((1, 8))

return output

Finally, it worked!

predictwise avatar Feb 26 '19 05:02 predictwise

@sakets594 @predictwise @take2rohit @156aasdfg @apiszcz highly recommend this repository. MultiGPU, multithreaded training, and comes with a very cool realtime-yolov3 iPhone app. https://github.com/ultralytics/yolov3

fourth-archive avatar Mar 28 '19 13:03 fourth-archive

still not working seems like it happens only for some images

some advance on this issue?

joaolcaas avatar Mar 29 '19 19:03 joaolcaas

The same error.................

nm46nm avatar Apr 11 '19 06:04 nm46nm

You might add if output.size()[1] == prediction.size()[1]: condition, beforeoutput = torch.cat((output,prediction)), inside detect.py

epm157 avatar Apr 15 '19 12:04 epm157

I fixed this problem in a ugly solution. The error was always reporting when detecting the image named "scream.jpg". Specifically, the right dimension returned from function "write_results" was [N, 8], however, the wrong dimension was [N, 86]. In addition, the result returned from function "write_results" contained many strange values, e.g. 6.9610e-45, -1.3956e+23, etc. Therefore, I add the following codes end the function "write_results": output[(output > 0) & (output < 0.00001)] = 0 output[output < -10000] = 0 output[output > 10000] = 0 if len(torch.nonzero(output)) < 1: return torch.zeros((1, 8))

return output

Finally, it worked!

Hello, I've got the same issue, but I can not find where the implement of "write_result" function it is. Can you help me? Thanks too much!

iPersevere avatar Jun 14 '19 01:06 iPersevere

@iPersevere it is in the util.py

predictwise avatar Jun 14 '19 02:06 predictwise

epm157's comment should be accepted as a pull request.

filamoon avatar Sep 03 '19 06:09 filamoon

I just deleted the scream image. That is the one giving the problem. All the other images seem to work.

FranciscoReveriano avatar Nov 05 '19 18:11 FranciscoReveriano

I just deleted the scream image. That is the one giving the problem. All the other images seem to work.

how should I know witch image drives this problem?thank u

Rocky-17 avatar Feb 17 '20 14:02 Rocky-17

I fixed this problem in a ugly solution. The error was always reporting when detecting the image named "scream.jpg". Specifically, the right dimension returned from function "write_results" was [N, 8], however, the wrong dimension was [N, 86]. In addition, the result returned from function "write_results" contained many strange values, e.g. 6.9610e-45, -1.3956e+23, etc. Therefore, I add the following codes end the function "write_results":

output[(output > 0) & (output < 0.00001)] = 0
output[output < -10000] = 0
output[output > 10000] = 0
if len(torch.nonzero(output)) < 1:
    return torch.zeros((1, 8))

return output

Finally, it worked!

Hello, In which line do I add the code?

Aaronponceuv avatar Feb 26 '20 16:02 Aaronponceuv

do not set the batch size to 1, you may try 2 or more

a better choice would be apply "if prediction.shape == (1,5+1+len(classes)):" instead of "#if type(prediction) == int:"

liaoyizhi123 avatar Mar 06 '20 13:03 liaoyizhi123

do not set the batch size to 1, you may try 2 or more

a better choice would be apply "if prediction.shape == (1,5+1+len(classes)):" instead of "#if type(prediction) == int:"

Thanks a lot!

igeng avatar Sep 04 '20 10:09 igeng