inference-and-postprocessing
Use this sub-skill for BiRefNet inference tasks that need:
- a Hugging Face load path or a local
.pthcheckpoint - image or directory-based mask generation
- foreground refinement or matting-style exports
- comparison panels and practical output validation
- notebook-style video inference guidance
Stay in scope
Use the bundled references and scripts when the task is about:
- loading BiRefNet weights for inference
- preparing
Resize+ToTensor+ ImageNet normalization - running
birefnet(input)[-1].sigmoid()in eval mode - saving masks, foregrounds, or comparison images
- understanding native
inference.pyoutput layout
Route elsewhere
- Model/backbone internals, patch helpers, or export mechanics →
../model-architecture/SKILL.md - Dataset layout or config defaults →
../configuration-and-data/SKILL.md - Training, evaluation, metrics, or checkpoint selection →
../training-and-evaluation/SKILL.md
Runtime entry points
references/inference-workflows.mdreferences/video-workflows.mdreferences/troubleshooting.mdscripts/birefnet_image_infer.pyscripts/birefnet_refine_smoke.py
Operating notes
- Start with
--helpor--dry-run. - Pass
--repo-rootexplicitly so imports stay anchored to the intended checkout. - Choose
--model-source localfor a checkpoint file or--model-source hffor hub weights. - Use
--device auto,cpu, orcudabased on the available backend. - Keep
--foreground-refineand--save-comparisonenabled when you need matting-style outputs. - Local checkpoints should be cleaned with
check_state_dictbefore loading; the helper does this for you.
Recommended operating flow
- Confirm whether the task is single image, directory, video, or repo-style dataset inference.
- Run
scripts/birefnet_refine_smoke.py --device cpuif the user only needs postprocessing/backend sanity before loading model weights. - Run
scripts/birefnet_image_infer.py --dry-runwith the intended image directory, output directory, model source, device, and resolution before a real inference run. - For local checkpoints, route persistent key or tensor-size mismatches to
../model-architecture/SKILL.md. - For outputs that will be evaluated with BiRefNet metrics, preserve dataset/model directory names that
../training-and-evaluation/SKILL.mdexpects.
Done criteria
- The model source and required assets are explicit: Hugging Face repo/cache or local
.pthcheckpoint. - The device, resolution, and CPU/CUDA/autocast limits are stated.
- The expected mask, foreground, and comparison output directories are known.
- Optional foreground refinement and video processing are separated from the core mask inference step.
Output conventions
- Masks go to
masks/ - Foreground/matting exports go to
foregrounds/ - Comparison panels go to
comparisons/ - Relative folder structure under
--inputis preserved