Ist Torch :: JIT :: Trace in Libtorch nicht verfügbar?C++

Programme in C++. Entwicklerforum
Anonymous
 Ist Torch :: JIT :: Trace in Libtorch nicht verfügbar?

Post by Anonymous »

Ich verwende libtorch in C ++. : Jit :: Trace funktioniert nicht in libtorch. ist mein einfacher Beispielcode. < /p>
#include
#include
#include

struct MyNetImpl : torch::nn::Module {
torch::nn::Linear fc{ nullptr };
MyNetImpl(int in_features, int out_features) {
fc = register_module("fc", torch::nn::Linear(in_features, out_features));
}
torch::Tensor forward(torch::Tensor x) {
return torch::relu(fc->forward(x));
}
};
TORCH_MODULE(MyNet);

int main() {
MyNet model(10, 2);
model->eval();

// Create an example input
auto example_input = torch::randn({ 1, 10 });

// NOTE: torch::jit::trace is a function:
auto traced_model = torch::jit::trace(model, example_input);

// Save TorchScript module
traced_model.save("model_traced.pt");
std::cout
Mein Code ist falsch oder Torch :: Jit :: Trace ist nicht in Libtorch verfügbar? in C ++ und laden Sie es in Python.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post