CorridorKey README

The project's README from github.com/nikopueringer/CorridorKey. As one markdown file: README.md.

CorridorKey

https://github.com/user-attachments/assets/1fb27ea8-bc91-4ebc-818f-5a3b5585af08

When you film something against a green screen, the edges of your subject inevitably blend with the green background. This creates pixels that are a mix of your subject's color and the green screen's color. Traditional keyers struggle to untangle these colors, forcing you to spend hours building complex edge mattes or manually rotoscoping. Even modern "AI Roto" solutions typically output a harsh binary mask, completely destroying the delicate, semi-transparent pixels needed for a realistic composite.

I built CorridorKey to solve this unmixing problem.

You input a raw green screen frame, and the neural network completely separates the foreground object from the green screen. For every single pixel, even the highly transparent ones like motion blur or out-of-focus edges, the model predicts the true, un-multiplied straight color of the foreground element, alongside a clean, linear alpha channel. It doesn't just guess what is opaque and what is transparent; it actively reconstructs the color of the foreground object as if the green screen was never there.

No more fighting with garbage mattes or agonizing over "core" vs "edge" keys. Give CorridorKey a hint of what you want, and it separates the light for you.

Alert!

This is a brand new release, I'm sure you will discover many ways it can be improved! I invite everyone to help. Join us on the "Corridor Creates" Discord to share ideas, work, forks, etc! https://discord.gg/zvwUrdWXJm

If you want an easy-install, artist-friendly user interface version of CorridorKey, check out EZ-CorridorKey

This project uses uv to manage dependencies — it handles Python installation, virtual environments, and packages all in one step, so you don't need to worry about any of that. Just run the appropriate install script for your OS.

Naturally, I have not tested everything. If you encounter errors, please consider patching the code as needed and submitting a pull request.

Features

Hardware Requirements

This project was designed and built on a Linux workstation (Puget Systems PC) equipped with an NVIDIA RTX Pro 6000 with 96GB of VRAM. The community is ACTIVELY optimizing it for consumer GPUS.

The most recent build should work on computers with 6-8 gig of VRAM, and it can run on most M1+ Mac systems with unified memory. Yes, it might even work on your old Macbook pro. Let us know on the Discord!

Because GVM and VideoMaMa have huge model file sizes and extreme hardware requirements, installing their modules is completely optional. You can always provide your own Alpha Hints generated from your editing program, BiRefNet, or any other method. The better the AlphaHint, the better the result.

Getting Started

1. Installation

This project uses uv to manage Python and all dependencies. uv is a fast, modern replacement for pip that automatically handles Python versions, virtual environments, and package installation in a single step. You do not need to install Python yourself — uv does it for you.

For Windows Users (Automated):

  1. Clone or download this repository to your local machine.
  2. Double-click Install_CorridorKey_Windows.bat. This will automatically install uv (if needed), set up your Python environment, install all dependencies, and download the CorridorKey model.

    Note: If this is the first time installing uv, any terminal windows you already had open won't see it. The installer script handles the current window automatically, but if you open a new terminal and get "'uv' is not recognized", just close and reopen that terminal.

  3. (Optional) Double-click Install_GVM_Windows.bat and Install_VideoMaMa_Windows.bat to download the heavy optional Alpha Hint generator weights.

For Linux / Mac Users (Automated):

  1. Clone or download this repository to your local machine.
  2. Open terminal and write bash. Put a space after writing bash.
  3. Drag and drop Install_CorridorKey_Linux_Mac.sh into the terminal. Then press enter.
  4. (Optional) Do the 2. step again. But now drag and drop Install_GVM_Linux_Mac.sh and Install_VideoMaMa_Linux_Mac.sh to download the heavy optional Alpha Hint generator weights.

For Linux / Mac Users (Manual):

  1. Clone or download this repository to your local machine.
  2. Install uv if you don't have it:
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  3. Install all dependencies (uv will download Python 3.10+ automatically if needed):
    uv sync                  # CPU/MPS (default — works everywhere)
    uv sync --extra cuda     # CUDA GPU acceleration (Linux/Windows)
    uv sync --extra mlx      # Apple Silicon MLX acceleration
    
    For AMD ROCm setup, see the AMD ROCm Setup section below.
  4. Download the Models:
    • CorridorKey v1.0 Model (~300MB): Downloads automatically on first run. If no checkpoint is found in CorridorKeyModule/checkpoints/, the engine fetches it from CorridorKey's HuggingFace and saves it as CorridorKey_v1.0.safetensors (preferred — safer, no pickle). Legacy .pth files are still loaded automatically if already present. No manual download needed.
    • CorridorKeyBlue 1.0 Model (~300MB): Dedicated blue-screen checkpoint. Downloaded on demand the first time you run with --screen-color blue (or when auto-detection picks blue) from CorridorKeyBlue's HuggingFace, saved as CorridorKeyBlue_1.0.safetensors. The two models coexist in checkpoints/ and are picked automatically per clip.
    • GVM Weights (Optional): HuggingFace: geyongtao/gvm
      • Download using the CLI: uv run hf download geyongtao/gvm --local-dir gvm_core/weights
    • VideoMaMa Weights (Optional): HuggingFace: SammyLim/VideoMaMa
      • Download the VideoMaMa fine-tuned weights:
        uv run hf download SammyLim/VideoMaMa --local-dir VideoMaMaInferenceModule/checkpoints/VideoMaMa
        
      • VideoMaMa also requires the Stable Video Diffusion base model (VAE + image encoder only, ~2.5GB). Accept the license at stabilityai/stable-video-diffusion-img2vid-xt, then:
        uv run hf download stabilityai/stable-video-diffusion-img2vid-xt \
          --local-dir VideoMaMaInferenceModule/checkpoints/stable-video-diffusion-img2vid-xt \
          --include "feature_extractor/*" "image_encoder/*" "vae/*" "model_index.json"
        
      • VideoMaMa is an amazing project, please go star their repo and show them some support!

2. How it Works

CorridorKey requires two inputs to process a frame:

  1. The Original RGB Image: The to-be-processed green or blue screen footage. This requires the sRGB color gamut (interchangeable with REC709 gamut), and the engine can ingest either an sRGB gamma or Linear gamma curve.
  2. A Coarse Alpha Hint: A rough black-and-white mask that generally isolates the subject. This does not need to be precise. It can be generated by you with a rough chroma key or AI roto.

By default the screen color is auto-detected from the first frame's background pixels (where the alpha hint is dark). Pass --screen-color green or --screen-color blue to skip detection and force a specific checkpoint.

I've had the best results using GVM or VideoMaMa to create the AlphaHint, so I've repackaged those projects and integrated them here as optional modules inside clip_manager.py. Here is how they compare:

Perhaps in the future, I will implement other generators for the AlphaHint! In the meantime, the better your Alpha Hint, the better CorridorKey's final result will be. Experiment with different amounts of mask erosion or feathering. The model was trained on coarse, blurry, eroded masks, and is exceptional at filling in details from the hint. However, it is generally less effective at subtracting unwanted mask details if your Alpha Hint is expanded too far.

Please give feedback and share your results!

Docker (Linux + NVIDIA GPU)

If you prefer not to install dependencies locally, you can run CorridorKey in Docker.

Prerequisites:

  1. Build the image:
    docker build -t corridorkey:latest .
    
  2. Run an action directly (example: inference):
    docker run --rm -it --gpus all \
      -e OPENCV_IO_ENABLE_OPENEXR=1 \
      -v "$(pwd)/ClipsForInference:/app/ClipsForInference" \
      -v "$(pwd)/Output:/app/Output" \
      -v "$(pwd)/CorridorKeyModule/checkpoints:/app/CorridorKeyModule/checkpoints" \
      -v "$(pwd)/gvm_core/weights:/app/gvm_core/weights" \
      -v "$(pwd)/VideoMaMaInferenceModule/checkpoints:/app/VideoMaMaInferenceModule/checkpoints" \
      corridorkey:latest run_inference --device cuda
    
  3. Docker Compose (recommended for repeat runs):
    docker compose build
    docker compose --profile gpu run --rm corridorkey run_inference --device cuda
    docker compose --profile gpu run --rm corridorkey list
    docker compose --profile cpu run --rm corridorkey-cpu run_inference --device cpu
    
  4. Optional: pin to specific GPU(s) for multi-GPU workstations:
    NVIDIA_VISIBLE_DEVICES=0 docker compose --profile gpu run --rm corridorkey list
    NVIDIA_VISIBLE_DEVICES=1,2 docker compose --profile gpu run --rm corridorkey run_inference --device cuda
    

Notes:

3. Usage: The Command Line Wizard

For the easiest experience, use the provided launcher scripts. These scripts launch a prompt-based configuration wizard in your terminal.

Workflow Steps:

  1. Launch: You can drag-and-drop a single loose video file (like an .mp4), a shot folder containing image sequences, or even a master "batch" folder containing multiple different shots all at once onto the launcher script.
  2. Organization: The wizard will detect what you dragged in. If you dropped loose video files or unorganized folders, the first prompt will ask if you want it to organize your clips into the proper structure.
    • If you say Yes, the script will automatically create a shot folder, move your footage into an Input/ sub-folder, and generate empty AlphaHint/ and VideoMamaMaskHint/ folders for you. This structure is required for the engine to pair your hints and footage correctly!
  3. Generate Hints (Optional): If the wizard detects your shots are missing an AlphaHint, it will ask if you want to generate them automatically using the repackaged GVM or VideoMaMa modules.
  4. Configure: Once your clips have both Inputs and AlphaHints, select "Process Ready Clips". The wizard will prompt you to configure the run:
    • Gamma Space: Tell the engine if your sequence uses a Linear or sRGB gamma curve.
    • Despill Strength: This is a traditional despill filter (0-10), if you wish to have it baked into the output now as opposed to applying it in your comp later.
    • Auto-Despeckle: Toggle automatic cleanup and define the size threshold. This isn't just for tracking dots, it removes any small, disconnected islands of pixels.
    • Refiner Strength: Use the default (1.0) unless you are experimenting with extreme detail pushing.
  5. Result: The engine will generate several folders inside your shot directory:
    • /Matte: The raw Linear Alpha channel (EXR).
    • /FG: The raw Straight Foreground Color Object. (Note: The engine natively computes this in the sRGB gamut. You must manually convert this pass to linear gamma before being combined with the alpha in your compositing program).
    • /Processed: An RGBA image containing the Linear Foreground premultiplied against the Linear Alpha (EXR). This pass exists so you can immediately drop the footage into Premiere/Resolve for a quick preview without dealing with complex premultiplication routing. However, if you want more control over your image, working with the raw FG and Matte outputs will give you that.
    • /Comp: A simple preview of the key composited over a checkerboard (PNG).

But What About Training and Datasets?

If enough people find this project interesting I'll get the training program and datasets uploaded so we can all really go to town making the absolute best keyer fine tunes! Just hit me with some messages on the Corridor Creates discord or here. If enough people lock in, I'll get this stuff packaged up. Hardware requirements are beefy and the gigabytes are plentiful so I don't want to commit the time unless there's demand.

Device Selection

By default, CorridorKey auto-detects the best available compute device: CUDA > MPS > CPU.

Override via CLI flag:

uv run python clip_manager.py --action wizard --win_path "V:\..." --device mps
uv run python clip_manager.py --action run_inference --device cpu

Override via environment variable:

export CORRIDORKEY_DEVICE=cpu
uv run python clip_manager.py --action wizard --win_path "V:\..."

Priority: --device flag > CORRIDORKEY_DEVICE env var > auto-detect.

Apple Silicon / MPS Troubleshooting

Confirm MPS is active: Run with verbose logging to see which device was selected:

uv run python clip_manager.py --action list 2>&1 | grep -i "device\|backend\|mps"

MPS operator errors (NotImplementedError: ... not implemented for 'MPS'): Some PyTorch operations are not yet supported on MPS. Enable CPU fallback for those ops:

export PYTORCH_ENABLE_MPS_FALLBACK=1
uv run python corridorkey_cli.py wizard --win_path "/path/to/clips"

Silent CPU fallback: If MPS silently falls back to CPU without this variable, the run will be much slower. Setting PYTORCH_ENABLE_MPS_FALLBACK=1 in your shell profile (~/.zshrc) ensures it is always active.

Use native MLX instead of PyTorch MPS: MLX avoids PyTorch's MPS layer entirely and typically runs faster on Apple Silicon. See the Backend Selection section below for setup steps.

AMD ROCm Setup

CorridorKey supports AMD GPUs via PyTorch's ROCm/HIP backend. The torch.cuda.* API works transparently on AMD — HIP intercepts all CUDA calls at runtime, so the inference code runs unchanged.

Supported GPUs (ROCm 7.2+):

VRAM requirements: CorridorKey inference at 2048x2048 uses ~10GB on NVIDIA but ~18GB on AMD due to HIP allocator overhead. The RX 7900 XTX (24GB) and RX 7900 XT (20GB) run at full resolution. Cards with 16GB (RX 7800 XT, 9070 XT) work on Windows (which uses system RAM as overflow) but may OOM on Linux — see notes below.

Linux native (recommended):

uv sync --extra rocm

# Verify
uv run python -c "import torch; print(torch.cuda.is_available(), to

CorridorKey (nikopueringer/CorridorKey)

Searching Database…

这是什么?CorridorKey 是一款基于神经网络的工具,可对绿幕或蓝幕素材进行抠像。它会为每个像素预测真实的、未预乘的前景颜色,以及干净的线性 Alpha 通道,包括运动模糊或焦外边缘等半透明像素。
这是图形界面应用还是命令行工具?它是一个 Python 命令行工具,通过交互式的拖放向导脚本来运行,不是打包好的桌面应用。如果你更想要图形界面,可以使用另一个安装更简单的 GUI 版本,名为 EZ-CorridorKey。
我该怎么让它跑起来?克隆仓库,然后运行适用于你操作系统的安装脚本(在 Windows 上可双击 InstallCorridorKeyWindows.bat,在 Linux/Mac 上运行 InstallCorridorKeyLinuxMac.sh)。脚本会使用 uv 自动配置 Python 和所有依赖。对于配有 NVIDIA GPU 的 Linux,也可以使用 Docker + Compose 的方式。
抠一段素材,我得自己装 Python 或别的什么吗?不需要,uv 会替你安装 Python。但要处理一段素材,你需要两样输入:原始的绿幕或蓝幕素材,以及粗略 Alpha 提示(Coarse Alpha Hint)遮罩。后者可以手动制作,也可以用可选模块 GVM、VideoMaMa 或 BiRefNet 生成。
刚发布不久,是不是还有些粗糙的地方?是的。这是一个全新发布的版本,作者承认它尚未在所有环境中充分测试,所以你可能会遇到 bug。目前它也只支持 Torch 后端;至于 Apple MLX 路径,在蓝幕检查点发布之前,仍只能处理绿幕。
运行时需要联网吗?CorridorKey 模型约 300MB,首次运行时会自动从 HuggingFace 下载,因此至少需要联网一次。之后推理会在你的本地机器上运行。
运行它需要什么样的显卡?Windows 需要支持 CUDA 12.8+ 的 NVIDIA 驱动才能使用原生 GPU 加速;AMD RX 7000/9000 系列可在 Linux 上通过 ROCm 运行;较新的构建版本可在 6-8GB 显存的设备上运行,甚至可以在 M1 及以上型号的 Mac 上运行。作者自己的机器使用的是 96GB 的 RTX Pro 6000。
在 Alpha 提示上,使用 GVM 和 VideoMaMa 有什么区别?GVM 全程自动运行,处理人物效果很好,但对无生命物体可能效果不佳;VideoMaMa 则需要你提供粗略的手绘或 AI 遮罩提示,但结果的可控性更强、质量更高。
它能处理 4K 素材吗?能。引擎会动态调整推理规模来处理 4K 素材,同时通过其原生的 2048x2048 高保真主干网络进行预测。
它为特效制作输出哪些文件格式?它原生支持读写 16 位和 32 位线性浮点 EXR 文件,保留真实的色彩运算结果,便于在 Nuke、Fusion 或 Resolve 中使用。
它能像抠绿幕一样抠蓝幕吗?可以。它内置了专门的蓝幕检查点,传入 --screen-color blue 参数时会自动下载;或者它也能根据第一帧自动识别屏幕颜色。
Size
39.6 MB
Stars
14.9K
Updated
CommitMay 28
Age
7mo
Commits · 90 Days