pytorch - 手电筒 C++ : API to check NAN

标签 pytorch torch libtorch

我正在使用 libtorch C++。在 python 版本中,我们可以通过调用其 numpy 值轻松检查张量的值,而在 numpy 中,我们有 np.isnan()。我想知道 libtorch C++ 中是否有内置函数来检查张量是否有任何 NAN 值?

谢谢, 阿夫欣

最佳答案

添加 Fábio 的回答(我的声誉太低无法发表评论):

如果您真的想在 assertif 条件中使用有关 NAN 的信息,您需要将其从 torch::Tensor 转换而来像这样的 C++ bool

torch::Tensor myTensor;
// do something
auto tensorIsNan = at::isnan(myTensor).any().item<bool>(); // will be of type bool

关于pytorch - 手电筒 C++ : API to check NAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54205116/

相关文章:

torch - pytorch自定义层 "is not a Module subclass"

machine-learning - 调用向后时 nn.CDivTable 抛出错误是否有正当理由?

c++ - PyTorch C++ 前端向前返回多个张量

c++ - 如何将std::vector <std::vector <double >>转换为Torch::Tensor?

audio - CNN之后的LSTM如何馈入以及什么维度(输入大小)?

python - 不更新权重的反向传播(DCGAN)

python - 在 PyTorch 中,nll_loss 的输入是什么?

python - 类型错误 : '<' not supported between instances of 'torch.device' and 'int'

c++ - 在Windows上构建pytorch时出现C1001内部编译器错误

permissions - PyTorch 权限错误 : [Errno 13] Permission denied: '/.torch'