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};
58 SOFIE::RModel model = SOFIE::PyTorch::Parse(
"PyTorchModel.pt",inputShapesSequential);
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);
R__EXTERN TSystem * gSystem
const ETensorType & GetTensorType(std::string name)
void Generate(bool useSession=true, bool useWeightFile=true)
void PrintIntermediateTensors()
bool CheckIfTensorAlreadyExist(std::string tensor_name)
void PrintInitializedTensors()
void OutputGenerated(std::string filename="")
const std::vector< size_t > & GetTensorShape(std::string name)
void PrintRequiredInputTensors()
static void PyInitialize()
Initialize Python interpreter.
Class supporting a collection of lines with C++ code.
virtual TObjString * AddLine(const char *text)
Add line with text in the list of lines of this macro.
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...