等效于火炬。
我正在尝试将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 objectself.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要注册一个参数(或需要梯度的张量)到模块,您可以使用:
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.