portrait-workflows
Run U-2-Net portrait drawing, own-image face-crop portrait inference, and portrait/original compositing workflows.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- portrait-workflows
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Run U-2-Net portrait drawing, own-image face-crop portrait inference, and portrait/original compositing workflows.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/api-reference.md2.6 KB
- 参考文档references/troubleshooting.md2.3 KB
- 参考文档references/workflows.md3.3 KB
- 脚本scripts/haarcascade_frontalface_default.xml908.3 KB
- 脚本scripts/portrait_composite.py6.8 KB
- 脚本scripts/portrait_infer.py9.0 KB
03 SKILL.md 正文
Portrait Workflows
Use this sub-skill when the task is portrait drawing/generation with the U-2-Net portrait checkpoint, own-photo face-crop portrait inference, Haar-cascade handling, or portrait/original composite images with explicit blur and blend controls.
Start here
- Choose the portrait workflow in workflows: APDrawingGAN-style portrait-set inference, own-image face-crop inference, or portrait/original compositing.
- Run the bundled helpers instead of original demo scripts:
scripts/portrait_infer.pyfor portrait-set and own-image portrait maps.scripts/portrait_composite.pyfor Gaussian-blurred original plus portrait-map composites.
- Supply explicit
u2net_portrait.pth-compatible weights with--weights; pretrained portrait weights are not bundled. - Use troubleshooting when weights, OpenCV, cascade parsing, CUDA selection, no-face fallback, alpha/sigma validation, or image quality is the problem.
Common routes
- APDrawingGAN-style portrait inputs: use
portrait_infer.py --mode portrait-set. Inputs should already be split/cropped portrait images, commonly 512x512. - Own photos: use
portrait_infer.py --mode own-images. It uses the bundled Haar cascade by default, selects the largest face, crops/pads/resizes to 512, and falls back to the whole image if no face is found. - Composite style: use
portrait_composite.py --sigma 20 --alpha 0.5or other explicit values. It writes*_sigma_<sigma>_alpha_<alpha>_composite.pngwith numeric punctuation sanitized for portability. - Plumbing-only smoke checks: add
--allow-random-weights-for-smoke --max-images 1 --device cpuonly to verify imports, preprocessing, forward pass, and output writing. Do not treat random-weight outputs as portrait quality evidence.
Quality constraints
For own photos, high-quality portrait drawing requires the head region to be close to or larger than 512x512 and the head background to be relatively clear. Small, blurry, occluded, profile, crowded, or cluttered photos may run but usually produce weak portraits.
Boundaries
- Generic salient-object masks, background removal, and human/person masks route to
salient-object-inference. - Architecture internals, side-output semantics, model variant choice, and checkpoint-shape diagnosis route to
model-architecture. - Dataset construction, augmentation, retraining, loss wiring, and long training runs route to
data-and-training.
Minimal commands
Portrait-set inference:
python scripts/portrait_infer.py \
--weights PATH_TO_WEIGHTS/u2net_portrait.pth \
--input-dir INPUT_PORTRAITS \
--output-dir PORTRAIT_RESULTS \
--mode portrait-set \
--device auto
Own-image inference with the bundled cascade:
python scripts/portrait_infer.py \
--weights PATH_TO_WEIGHTS/u2net_portrait.pth \
--input-dir OWN_IMAGES \
--output-dir YOUR_PORTRAIT_RESULTS \
--mode own-images \
--device auto
Composite with README-style parameters:
python scripts/portrait_composite.py \
--weights PATH_TO_WEIGHTS/u2net_portrait.pth \
--input-dir OWN_IMAGES \
--output-dir COMPOSITE_RESULTS \
--sigma 20 \
--alpha 0.5 \
--device auto
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).