About converting loss.data.cpu().numpy() from pytorch to libtorch

Hi, All, I have met an issue about converting the following from pytorch to libtorch (C++)

In pytorch it is:
return loss.data.cpu().numpy()

I write in C++ as:
return loss.data.cpu().numpy();

I get error no member “numpy()” for at::Tensor

Any suggestions ?
Much appreciated

You cannot transform the tensor to a numpy array, since numpy doesn’t have a C++ API.

Thanks.

So I will just convert it as: return loss.data().cpu();

Are they the same in this case ?

Best,
Xu

Yes, but with the catch that you would still be returning a tensor.