15import torch.nn as nn\n\
17model = nn.Sequential(\n\
24criterion = nn.MSELoss()\n\
25optimizer = torch.optim.SGD(model.parameters(),lr=0.01)\n\
30for i in range(500):\n\
32 loss = criterion(y_pred,y)\n\
33 optimizer.zero_grad()\n\
38m = torch.jit.script(model)\n\
39torch.jit.save(m,'PyTorchModel.pt')\n";
42void TMVA_SOFIE_PyTorch(){
49 m.SaveSource(
"make_pytorch_model.py");
54 std::vector<size_t> inputTensorShapeSequential{2,32};
55 std::vector<std::vector<size_t>> inputShapesSequential{inputTensorShapeSequential};
62 model.OutputGenerated(
"PyTorchModel.hxx");
66 model.PrintRequiredInputTensors();
70 model.PrintInitializedTensors();
74 model.PrintIntermediateTensors();
77 std::cout<<
"\n\nTensor \"0weight\" already exist: "<<std::boolalpha<<
model.CheckIfTensorAlreadyExist(
"0weight")<<
"\n\n";
78 std::vector<size_t> tensorShape =
model.GetTensorShape(
"0weight");
79 std::cout<<
"Shape of tensor \"0weight\": ";
80 for(
auto& it:tensorShape){
83 std::cout<<
"\n\nData type of tensor \"0weight\": ";
85 std::cout<<SOFIE::ConvertTypeToString(tensorType);
89 model.PrintGenerated();
R__EXTERN TSystem * gSystem
static void PyInitialize()
Initialize Python interpreter.
Class supporting a collection of lines with C++ code.
virtual Int_t Exec(const char *shellcmd)
Execute a command.
TString Python_Executable()
Function to find current Python executable used by ROOT If Python2 is installed return "python" Inste...