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:

  1. Installs system dependencies including ffmpeg and libgl1-mesa-glx
  2. Copies the entire repository into /rife inside the container
  3. Installs Python requirements from requirements.txt (including PyTorch)
  4. Sets the environment variable ENV NVIDIA_DRIVER_CAPABILITIES all to ensure the NVIDIA runtime exposes all driver capabilities to the container
  5. Configures /bin/bash as 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 all exposes all host GPUs to the container using the NVIDIA Container Toolkit
  • -v /dev/dri:/dev/dri bind-mounts the Direct Rendering Infrastructure device for GPU access
  • -v "$(pwd)":/host mounts your current working directory (containing input images and the train_log/ model directory) to /host inside the container
  • --exp 4 specifies (2^4 = 16)× frame interpolation
  • The inference_img wrapper invokes inference_img.py, which automatically selects GPU execution when torch.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:

  1. Driver Capability Exposure: The ENV NVIDIA_DRIVER_CAPABILITIES all setting in docker/Dockerfile instructs the NVIDIA Container Toolkit to expose compute, utility, and graphics capabilities to the container.

  2. Runtime GPU Selection: Both inference_img.py and inference_video.py check torch.cuda.is_available() to automatically select CUDA execution when GPUs are present. No manual device specification is required.

  3. Entrypoint Wrappers: The shell scripts at docker/inference_img and docker/inference_video serve 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 the train_log/ directory via volume mapping -v "$(pwd)":/host.
  • Enable GPU acceleration by running containers with --gpus all and -v /dev/dri:/dev/dri to expose host NVIDIA drivers to the PyTorch backend.
  • Execute inference using the wrapper scripts inference_img or inference_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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →