preprocessing
Operate Photo2Cartoon face alignment, crop, segmentation-mask, alpha, and whitening preprocessing contracts.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- preprocessing
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Operate Photo2Cartoon face alignment, crop, segmentation-mask, alpha, and whitening preprocessing contracts.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/preprocessing-pipeline.md8.8 KB
- 参考文档references/troubleshooting.md8.3 KB
- 脚本scripts/build_preprocess_command.py2.9 KB
- 脚本scripts/preprocess_contract_check.py11.2 KB
03 SKILL.md 正文
preprocessing
Use this sub-skill when a task needs the Photo2Cartoon preprocessing contract: face landmark detection, largest-face selection, eye-corner rotation alignment, expanded square face crop, TensorFlow segmentation-mask handling, RGBA composition, or white-background compositing before training or portrait inference.
Route Map
- Use this sub-skill for
Preprocess.process,FaceDetect.align, crop expansion ratios, detector selection (dliborsfd), segmentation graph tensor names, and alpha-mask semantics. - Route generator execution, PyTorch/ONNX model weights, Cog prediction, and cartoon output postprocessing to sibling sub-skill
portrait-inference. - Route dataset directory layout, batch data preparation policy, and training CLI/checkpoint behavior to sibling sub-skill
data-and-training.
First Steps
- Confirm the input image is RGB
uint8with shapeH x W x 3; convert OpenCVBGRinputs to RGB before calling preprocessing. - Confirm external preprocessing assets are available when doing real segmentation: the portrait segmentation graph is named
seg_model_384.pband is expected beside the preprocessing utilities in a repo checkout. It is not bundled in this skill. - Choose face-alignment backend deliberately:
detector='dlib'is the default;detector='sfd'may be useful when installed and supported by the localface_alignmentpackage. Usedevice='cuda'only when the detector stack and PyTorch/TensorFlow stack are GPU-compatible. - For source-contract checks that do not import TensorFlow, dlib, or the repo package, run the bundled checker:
python scripts/preprocess_contract_check.py --help
python scripts/preprocess_contract_check.py --repo-root /path/to/photo2cartoon-checkout
- For batch preprocessing, build a guarded command with the bundled helper and add
--executeonly after assets/dependencies are verified:
python scripts/build_preprocess_command.py \
--repo-root /path/to/photo2cartoon-checkout \
--data-path /path/to/raw-portrait-folder \
--save-path /path/to/preprocessed-output-folder
Runtime Contract
Preprocess.process(image)returnsNonewhen no face landmarks are detected.- On success it returns an
Hc x Wc x 4uint8-style RGBA array: first three channels are the aligned/cropped RGB face, and channel 4 is the resized segmentation alpha mask. - The crop stage fills out-of-frame regions with white (
255) before inserting the visible source pixels, so border padding is expected for near-edge faces. - Background whitening uses
mask = alpha[:, :, None] / 255.0andface * mask + (1 - mask) * 255.
Read references/preprocessing-pipeline.md for the exact algorithm and API patterns. Read references/troubleshooting.md for missing assets, TensorFlow compatibility, detector installation, no/multiple-face handling, crop padding, and alpha-mask shape failures.
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).