等效于火炬。

发布于 2025-02-04 11:58:27 字数 383 浏览 2 评论 0原文

我正在尝试将Python Pytorch模型移植到C ++中的Libtorch。

在python中 self.a = nn.parameter(a)其中a是TORCH.TENSOR对象,带有quience> regightes_grad = true

对于C ++中的TORCH :: NN ::模块类中的TORCH :: TENSOR,这等于什么?

我的编辑器中的自动完成术中显示了类参数parameTerlist的类, 参数dictimpl,paramaterListimpl,但没有参数。我需要将其包装在1号列表中,还是我缺少其他东西。我无法从Google搜索或文档中找到所需的内容,但是我不确定要搜索什么。

I am trying to port a python PyTorch model to LibTorch in C++.

In python the line of code within a subclass of a torch.Module object
self.A = nn.Parameter(A) where A is a torch.tensor object with requires_grad=True.

What would be the equivalent of this for a torch::Tensor in a torch::nn::Module class in C++ ?

The autocomplete in my editor shows the classes ParameterDict, ParameterList,
ParameterDictImpl, ParamaterListImpl, but no Parameter. Do I need to wrap it in a list of size 1 or is there something else I'm missing. I wasn't able to find what I needed from a google search or the documentation, but I wasn't sure precisely what to search to be honest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫卆 2025-02-11 11:58:27

要注册一个参数(或需要梯度的张量)到模块,您可以使用:

m.register_parameter(“ a”,torch :: ons({20,1,5,5}),true);
在libtorch中。

To register a parameter (or tensor which requires gradients) to a module, you could use:

m.register_parameter("A", torch::ones({20, 1, 5, 5}), True);
in libtorch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文