Pytorch allow users to trace their nn.module or python functions and create executable or ScriptFunction. This scripts then can be called using pytorch built in methods like jit.load(). In this repo, a python nn model which also has user defined functions is traced and called in C++ using qmake.
- It depends on the models requirements check the requirements.txt file if provided by the authors
- Qt (5.15.2 Version is used in this repo)
- Libtorch
- C++ and OpenCv
For installation guides of tools in C++ side you can click on the required tool.
$ traced_model = torch.jit.trace(model_object, example_input)
$ traced_model.save('traced_model.pt')
$ Do not forget to change the paths defined in pro file
$ Place your traced model in debug folder of your project
$ Change line 17 according to your input model
$ Change line 29 to your video input
$ Run the main.cpp code to observe the output
This method is used to calculate the gradients in the traning phase. Since we are going to use the model in eval mode, we can change it to be regular forwarding function. Hence, if you encounter such a problem, convert function accordingly.