Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How could I fix this torch.zero() problem?

I’m trying to write a Logistic Regression by myself, but I found an error while initializing this torch.zero().

code:

w = torch.normal(0, 0.01, size=(2,1), requires_grad=True)
b = torch.zeros(1,require_grad=True) # Error occured here

Error message:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Traceback (most recent call last):
  File "linearRegression.py", line 37, in <module>
    b = torch.zeros(1,require_grad=True)
TypeError: zeros() received an invalid combination of arguments - got (int, require_grad=bool), but expected one of:
 * (tuple of ints size, *, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
 * (tuple of ints size, *, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)

>Solution :

You have a typo, change require_grad to requires_grad.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading