photo2cartoon
Guide Photo2Cartoon portrait cartoonization workflows: assets, preprocessing, PyTorch or ONNX inference, dataset preparation, GAN training, model internals, and troubleshooting.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- photo2cartoon
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Guide Photo2Cartoon portrait cartoonization workflows: assets, preprocessing, PyTorch or ONNX inference, dataset preparation, GAN training, model internals, and troubleshooting.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/repo-provenance.md2.1 KB
- 参考文档references/repo-routing-metadata.json423 B
- 参考文档references/setup-and-assets.md4.4 KB
- 参考文档references/troubleshooting.md3.8 KB
- 脚本scripts/check_repository_assets.py3.9 KB
03 SKILL.md 正文
Photo2Cartoon
Use this repo skill when a task names photo2cartoon, Photo2Cartoon, portrait cartoonization, face-to-cartoon translation, U-GAT-IT + Soft-AdaLIN hourglass models, the photo2cartoon_weights assets, or the repo's preprocessing/training scripts.
Photo2Cartoon is a source-script repository, not a packaged Python distribution. Treat the generated skill as the operating manual and use a target checkout or ported module set only when the user explicitly needs to execute the code.
First Checks
- Read
references/repo-provenance.mdbefore deciding whether this skill matches a current checkout. - Read
references/setup-and-assets.mdbefore installing dependencies or looking for weights. - Run the shared source/asset checker when a user supplies a checkout:
python scripts/check_repository_assets.py --root /path/to/photo2cartoon-checkout
- If the task requires full visual inference, confirm that external model files exist; this checkout did not contain the published
.pt,.onnx,.pb, or MobileFaceNet assets when the skill was generated.
Route by Task
| User task | Read |
|---|---|
Run or debug PyTorch .pt portrait inference, ONNX inference, output validation, or Cog-style prediction |
sub-skills/portrait-inference/SKILL.md |
| Explain or port face detection, largest-face selection, rotation alignment, crop expansion, segmentation mask, alpha composition, or background whitening | sub-skills/preprocessing/SKILL.md |
Prepare trainA/trainB/testA/testB folders, validate image data, understand data_process.py, or launch/resume GAN training |
sub-skills/data-and-training/SKILL.md |
Inspect ResnetGenerator, Discriminator, Soft-AdaLIN/LIN, checkpoint keys, Face ID loss, CAM heatmaps, or safe synthetic model checks |
sub-skills/model-internals/SKILL.md |
| Diagnose cross-cutting install/import, asset, backend, or legacy dependency problems | references/troubleshooting.md |
Core Operating Facts
- Inference first preprocesses a face into an aligned/cropped RGBA image, composites the RGB crop on white, resizes to
256x256, normalizes to[-1,1], runs the generator, and reuses the alpha mask over a white final background. - The PyTorch inference path constructs
ResnetGenerator(ngf=32, img_size=256, light=True)and loads checkpoint keygenA2Bfrommodels/photo2cartoon_weights.pt. - The ONNX path feeds input name
inputand requests output nameoutputfrommodels/photo2cartoon_weights.onnx. - Training expects
dataset/<dataset>/{trainA,trainB,testA,testB}with real photos in domain A and cartoon portraits in domain B. - The training object saves checkpoints with keys
genA2B,genB2A,disGA,disGB,disLA, anddisLB. - Full preprocessing and inference require external assets and legacy ML dependencies; safe generated helpers default to validation, recipe generation, or synthetic smoke checks rather than downloads or long training.
Bundled References and Scripts
references/setup-and-assets.md: dependency snapshots, external assets, and safe environment strategy.references/troubleshooting.md: cross-cutting failures before routing to a sub-skill.references/repo-routing-metadata.json: structured router metadata used by DisCo's repo-skill importer.scripts/check_repository_assets.py: safe source-tree and asset validator.
Non-goals
This skill does not bundle the model weights, segmentation graph, cartoon dataset, or sample images. It also does not verify visual quality, run the original long training loop, download data from cloud drives, or mutate a user's shared Python environment.
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).