ffmpeg/libavfilter/dnn
Wenbin Chen f4e0664fd1 libavfi/dnn: add LibTorch as one of DNN backend
PyTorch is an open source machine learning framework that accelerates
the path from research prototyping to production deployment. Official
website: https://pytorch.org/. We call the C++ library of PyTorch as
LibTorch, the same below.

To build FFmpeg with LibTorch, please take following steps as
reference:
1. download LibTorch C++ library in
 https://pytorch.org/get-started/locally/,
please select C++/Java for language, and other options as your need.
Please download cxx11 ABI version:
 (libtorch-cxx11-abi-shared-with-deps-*.zip).
2. unzip the file to your own dir, with command
unzip libtorch-shared-with-deps-latest.zip -d your_dir
3. export libtorch_root/libtorch/include and
libtorch_root/libtorch/include/torch/csrc/api/include to $PATH
export libtorch_root/libtorch/lib/ to $LD_LIBRARY_PATH
4. config FFmpeg with ../configure --enable-libtorch \
 --extra-cflag=-I/libtorch_root/libtorch/include \
 --extra-cflag=-I/libtorch_root/libtorch/include/torch/csrc/api/include \
 --extra-ldflags=-L/libtorch_root/libtorch/lib/
5. make

To run FFmpeg DNN inference with LibTorch backend:
./ffmpeg -i input.jpg -vf \
dnn_processing=dnn_backend=torch:model=LibTorch_model.pt -y output.jpg

The LibTorch_model.pt can be generated by Python with torch.jit.script()
api. https://pytorch.org/tutorials/advanced/cpp_export.html. This is
pytorch official guide about how to convert and load torchscript model.
Please note, torch.jit.trace() is not recommanded, since it does
not support ambiguous input size.

Signed-off-by: Ting Fu <ting.fu@intel.com>
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Reviewed-by: Guo Yejun <yejun.guo@intel.com>
2024-03-19 14:48:58 +08:00
..
dnn_backend_common.c libavfiter/dnn_backend_openvino: Add multiple output support 2023-12-16 21:50:16 +08:00
dnn_backend_common.h
dnn_backend_openvino.c all: use designated initializers for AVOption.unit 2024-02-14 14:53:41 +01:00
dnn_backend_tf.c libavfilter/dnn_interface: use dims to represent shapes 2024-01-28 11:18:06 +08:00
dnn_backend_torch.cpp libavfi/dnn: add LibTorch as one of DNN backend 2024-03-19 14:48:58 +08:00
dnn_interface.c libavfi/dnn: add LibTorch as one of DNN backend 2024-03-19 14:48:58 +08:00
dnn_io_proc.c libavfilter/dnn_interface: use dims to represent shapes 2024-01-28 11:18:06 +08:00
dnn_io_proc.h
Makefile libavfi/dnn: add LibTorch as one of DNN backend 2024-03-19 14:48:58 +08:00
queue.c
queue.h
safe_queue.c
safe_queue.h