background-matting-v2
Routes BackgroundMattingV2 tasks for background matting inference, export, and training workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- background-matting-v2
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Routes BackgroundMattingV2 tasks for background matting inference, export, and training workflows.
- disable-model-invocation
- true
02 资源文件 8
- 参考文档references/api-reference.md3.1 KB
- 参考文档references/backend-compatibility.md1.8 KB
- 参考文档references/data-formats.md1.5 KB
- 参考文档references/repo-provenance.md1.4 KB
- 参考文档references/repo-routing-metadata.json343 B
- 参考文档references/troubleshooting.md3.3 KB
- 参考文档references/workflows.md2.4 KB
- 脚本scripts/check_env.py3.3 KB
03 SKILL.md 正文
BackgroundMattingV2
BackgroundMattingV2 is a computer-vision repo for high-resolution background matting with a source-image / background-image pair. Use this root skill as a router, not as a full manual.
Start here
- Read
references/repo-provenance.mdwhen you need to check whether this skill still matches the repository checkout. - Run
scripts/check_env.pyfirst when you only need a quick import and tiny forward smoke. - Read
references/workflows.mdfor the high-level route map and the decision points between inference, export, and training. - Read
references/api-reference.mdfor verified model and dataset signatures. - Read
references/data-formats.mdbefore touchingdata_path.pyor paired foreground/alpha/background directories. - Read
references/backend-compatibility.mdbefore choosing PyTorch, TorchScript, or ONNX paths. - Read
references/troubleshooting.mdfor cross-cutting install, import, and backend issues.
Install and inspect
This repo is source-tree based rather than a packaged wheel. For inspection, create an isolated Python environment, install the runtime stack used by the repo workflows, and then import the source modules from a checkout of this repo. The verified inspection stack used for this skill was Python 3.11 with:
torch+ matchingtorchvisionkorniaopencv-pythononnxonnxruntimetensorboardtqdm
A quick smoke is:
python scripts/check_env.py --repo-root <repo-checkout> --device cuda
Use --device cpu when you only need importability and tiny forward coverage. Add onnx when you want the ONNX smoke helper to validate export support.
Route map
Inference and demo
Use sub-skills/inference-and-demo/ when the task is about:
inference_images.pyinference_video.pyinference_webcam.pyinference_speed_test.py- choosing model type, backbone, refine mode, device, or output types
- understanding source/background pairing and alignment behavior
Read sub-skills/inference-and-demo/SKILL.md for the trigger terms and linked
workflow helpers.
Export and backend compatibility
Use sub-skills/export-and-backends/ when the task is about:
export_torchscript.pyexport_onnx.py- TorchScript attribute hoisting
- ONNX patch crop/replace compatibility choices
- validating export/runtime combinations
Read sub-skills/export-and-backends/SKILL.md when you need conversion steps or
backend troubleshooting.
Training and data setup
Use sub-skills/training/ when the task is about:
train_base.pytrain_refine.pydata_path.py- paired foreground/alpha/background directory layout
- training checkpoints, logs, and benchmark evaluation
- CUDA/DDP assumptions and dataset-name selection
Read sub-skills/training/SKILL.md before configuring data paths or starting a
training run.
Public surface summary
The public source-root modules you are expected to know are model, dataset,
inference_utils, and data_path. The primary classes are MattingBase and
MattingRefine. The main inference CLIs work with source/background image or
video pairs and can optionally apply homographic alignment.
What not to do
- Do not send future agents back to the original repo docs or scripts when a bundled reference or script exists here.
- Do not assume training or webcam workflows are safe to run without the right hardware, data, and display devices.
- Do not treat CPU importability as proof of CUDA readiness.
Local entry points
scripts/check_env.pysub-skills/inference-and-demo/scripts/smoke_forward.pysub-skills/export-and-backends/scripts/check_export_support.pysub-skills/training/scripts/check_data_layout.py
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).