2/07/2023

RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.

 refer to code:


use

tensor.detach().numpy()

..

import torch

tensor1 = torch.tensor([1.0,2.0],requires_grad=True)

print(tensor1)
print(type(tensor1))

tensor1 = tensor1.detach().numpy()

print(tensor1)
print(type(tensor1))

..


Thank you.


No comments:

Post a Comment