Convert a pytorch saved dict (.pth) to a traced model (.pt) suitable for libtorch
Since everything must run a venv these days:
python3 -m venv venv
. venv/bin/activate
pip3 install -r requirements.txt
If all goes according to plan, within the venv CUDA will be available:
(venv) jay@ooboontwo:~/git/pth2pt$ python3
Python 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.cuda.is_available())
True
>>>
After that, just run pth2pt.py [input_pth] [output_pt] and there should be no output:
(venv) jay@ooboontwo:~/git/pth2pt$ python3 pth2pt.py /mnt/chainner/models/2xVHS2HD-RealPLKSR.pth /mnt/chainner/models/2xVHS2HD-RealPLKSR.pt
(venv) jay@ooboontwo:~/git/pth2pt$
So long as you're running my hacked ffmpeg, you should be able to pass that model to the sr filter with dnn_backend set to torch:
ffmpeg -y -i Assignment_Outer_Space.mpeg -vf 'sr=dnn_backend=torch:device=cuda:model=/mnt/chainner/models/2xVHS2HD-RealPLKSR.pt' -codec:v ffv1 -codec:a aac -ab 128k -ar 48000 test.mkv
NOTE If you don't pass device=cuda to the torch backend, it will use CPU and run slow af. If you don't immediately see the usual ^frame=\s*\d+ ffmpeg output, that's what you forgot.