How to Use Docker with GPU Acceleration for RIFE Inference
Run RIFE frame interpolation inside a Docker container by building the image from docker/Dockerfile, mounting your pre-trained models to train_log/, and launching with --gpus all to expose host NVIDIA drivers for GPU-accelerated inference.
The hzwer/eccv2022-rife repository provides a complete Docker setup for running RIFE (Real-Time Intermediate Flow Estimation) inference with GPU support. This guide explains how to build the container image, configure NVIDIA driver capabilities, and execute both image and video interpolation while leveraging your host GPU hardware.
Prerequisites for GPU-Accelerated RIFE Docker Setup
Before building the RIFE Docker image, ensure your system meets the following requirements:
- Docker Engine 19.03 or newer with the NVIDIA Container Toolkit installed
- NVIDIA GPU drivers compatible with your CUDA version on the host system
- NVIDIA Docker runtime configured as the default or available runtime
The RIFE Dockerfile uses python:3.8-slim as its base image, which is CPU-only, but relies on the host's NVIDIA driver stack exposed through Docker's GPU runtime to access CUDA capabilities inside the container.
Building the RIFE Docker Image
Clone the repository and build the image using the provided Dockerfile located at docker/Dockerfile:
git clone https://github.com/hzwer/ECCV2022-RIFE.git
cd ECCV2022-RIFE
docker build -t rife -f docker/Dockerfile .
The build process performs the following actions defined in docker/Dockerfile:
- Installs system dependencies including
ffmpegandlibgl1-mesa-glx - Copies the entire repository into
/rifeinside the container - Installs Python requirements from
requirements.txt(including PyTorch) - Sets the environment variable
ENV NVIDIA_DRIVER_CAPABILITIES allto ensure the NVIDIA runtime exposes all driver capabilities to the container - Configures
/bin/bashas the entrypoint for interactive use
Running RIFE Inference with GPU Acceleration in Docker
To execute inference with GPU support, you must run the container with the --gpus all flag and mount your input files and pre-trained models. The repository provides wrapper scripts at docker/inference_img and docker/inference_video that forward arguments to the Python inference scripts.
Image Interpolation
Place your pre-trained model files (.pkl) in the train_log/ directory at the repository root, then run:
docker run --rm -it \
--gpus all -v /dev/dri:/dev/dri \
-v "$(pwd)":/host \
rife:latest inference_img \
--img img0.png img1.png \
--exp 4 \
--model train_log
Key parameters explained:
--gpus allexposes all host GPUs to the container using the NVIDIA Container Toolkit-v /dev/dri:/dev/dribind-mounts the Direct Rendering Infrastructure device for GPU access-v "$(pwd)":/hostmounts your current working directory (containing input images and thetrain_log/model directory) to/hostinside the container--exp 4specifies (2^4 = 16)× frame interpolation- The
inference_imgwrapper invokesinference_img.py, which automatically selects GPU execution whentorch.cuda.is_available()returns true
Video Interpolation
For video files, use the inference_video wrapper:
docker run --rm -it \
--gpus all -v /dev/dri:/dev/dri \
-v "$(pwd)":/host \
rife:latest inference_video \
--video input.mp4 \
--exp 2 \
--model train_log \
--output output_4X.mp4
The inference_video.py script handles frame extraction, GPU-accelerated interpolation, and audio transfer (via the transferAudio function) to ensure the output video retains the original audio track.
Enabling Half-Precision for Faster Inference
To reduce memory bandwidth and increase throughput on GPUs with Tensor Cores (such as NVIDIA RTX series), add the --fp16 flag to either inference command:
docker run --rm -it \
--gpus all -v /dev/dri:/dev/dri \
-v "$(pwd)":/host \
rife:latest inference_video \
--video input.mp4 \
--exp 2 \
--fp16 \
--model train_log
The --fp16 flag enables half-precision floating point operations, which the underlying PyTorch implementation in inference_video.py and inference_img.py automatically applies when the flag is present.
How GPU Acceleration Works Inside the Container
The RIFE Docker setup leverages the host's NVIDIA driver stack through several coordinated mechanisms:
-
Driver Capability Exposure: The
ENV NVIDIA_DRIVER_CAPABILITIES allsetting indocker/Dockerfileinstructs the NVIDIA Container Toolkit to expose compute, utility, and graphics capabilities to the container. -
Runtime GPU Selection: Both
inference_img.pyandinference_video.pychecktorch.cuda.is_available()to automatically select CUDA execution when GPUs are present. No manual device specification is required. -
Entrypoint Wrappers: The shell scripts at
docker/inference_imganddocker/inference_videoserve as thin wrappers that forward all command-line arguments to their respective Python scripts, ensuring the Docker command interface matches the native Python interface.
Summary
- Build the RIFE Docker image using
docker build -t rife -f docker/Dockerfile .after cloning the hzwer/eccv2022-rife repository. - Mount your pre-trained model files (
.pkl) to thetrain_log/directory via volume mapping-v "$(pwd)":/host. - Enable GPU acceleration by running containers with
--gpus alland-v /dev/dri:/dev/drito expose host NVIDIA drivers to the PyTorch backend. - Execute inference using the wrapper scripts
inference_imgorinference_video, which automatically detect CUDA availability and support half-precision (--fp16) for faster RTX GPU performance.
Frequently Asked Questions
Do I need an NVIDIA GPU to use Docker with RIFE?
While the RIFE Docker container can run on CPU-only systems, GPU acceleration requires an NVIDIA GPU with compatible drivers on the host machine. The container uses torch.cuda.is_available() to automatically detect GPU presence, falling back to CPU execution if CUDA is unavailable. For production inference, an NVIDIA GPU is strongly recommended to achieve real-time frame interpolation performance.
How do I mount my pre-trained models in the RIFE Docker container?
Place your downloaded .pkl model files in a train_log/ directory at the repository root, then mount the current working directory to /host inside the container using -v "$(pwd)":/host. The inference scripts expect the --model argument to point to this mounted directory (e.g., --model train_log). This bind-mount approach ensures the container can access both your input media files and the trained model weights without copying them into the image.
Can I run RIFE Docker inference on CPU-only systems?
Yes, the RIFE Docker container will function on CPU-only hosts, but you must omit the --gpus all flag when running the container. The inference scripts in inference_img.py and inference_video.py automatically check for CUDA availability and execute on CPU if no GPU is detected. However, expect significantly slower processing times compared to GPU acceleration, especially for high-resolution video interpolation.
What Docker flags are required for GPU acceleration with RIFE?
To enable GPU acceleration, you must include three specific configurations in your docker run command: --gpus all to expose all host GPUs to the container, -v /dev/dri:/dev/dri to bind-mount the Direct Rendering Infrastructure device node, and ensure the image was built with ENV NVIDIA_DRIVER_CAPABILITIES all (already configured in the repository's docker/Dockerfile). These settings allow PyTorch inside the container to detect and utilize the host's NVIDIA drivers for CUDA acceleration.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →