model-architecture
Understand and safely smoke-test U-2-Net model variants, side outputs, builders, and checkpoint-loading decisions.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- model-architecture
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Understand and safely smoke-test U-2-Net model variants, side outputs, builders, and checkpoint-loading decisions.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md3.0 KB
- 参考文档references/model-overview.md2.8 KB
- 参考文档references/troubleshooting.md2.4 KB
- 脚本scripts/smoke_architecture.py3.9 KB
03 SKILL.md 正文
Model Architecture
Use this sub-skill when the task is to choose, instantiate, smoke-test, or diagnose U-2-Net model architectures. It covers the original U2NET and U2NETP classes, the refactored U2NET_full() and U2NET_lite() builders, seven-output forward semantics, and safe checkpoint/device loading decisions.
Route elsewhere
- Full image-to-mask saliency or human-segmentation inference belongs to
salient-object-inference. - Portrait preprocessing, face crops, portrait prediction, and compositing belong to
portrait-workflows. - Dataset transforms, training layout, loss wiring, or long training runs belong to
data-and-training.
Quick operating facts
- U-2-Net is a script-style PyTorch repository, not an installable package with distribution metadata. Architecture checks against a local checkout should pass that checkout explicitly with
--repo-root. - Original models:
model.U2NET(in_ch=3, out_ch=1)andmodel.U2NETP(in_ch=3, out_ch=1). - Refactored builders:
model.u2net_refactor.U2NET_full()andmodel.u2net_refactor.U2NET_lite(). - A 3-channel input tensor shaped
(N, 3, H, W)produces seven sigmoid probability maps. Forout_ch=1, each output is shaped(N, 1, H, W). The first output is the fused prediction; the remaining six are side outputs. - Prefer
U2NETP(3, 1)for quick CPU smoke tests. UseU2NET(3, 1)for official full-size, human-segmentation, and portrait checkpoints unless a checkpoint explicitly targetsU2NETP.
References and scripts
- API reference: exact constructors, forward-output semantics, and safe checkpoint-loading snippets.
- Model overview: RSU/REBNCONV building-block summary and architecture selection guidance.
- Troubleshooting: wrong checkpoint, missing dependencies, CUDA confusion, deprecated upsample warnings, and output-shape surprises.
scripts/smoke_architecture.py: run this to verify imports and a tiny forward pass without pretrained weights.
Safe architecture smoke test
python scripts/smoke_architecture.py \
--model u2netp \
--height 64 \
--width 64 \
--device cpu
The command prints JSON with the selected device, input shape, output count, and output tensor shapes. Request --device cuda only when the local PyTorch build reports CUDA as available; otherwise the helper fails clearly instead of silently falling back.
Decision checklist
- Need only a fast structural check? Use
--model u2netp --device cpu. - Need compatibility with
u2net.pth, human segmentation, or portrait weights? InstantiateU2NET(3, 1)unless evidence says the checkpoint targetsU2NETP. - Seeing checkpoint mismatches? Check architecture variant,
out_ch, original-vs-refactor implementation, and CPU/CUDAmap_locationbefore changingstrictloading. - Seeing unexpected output handling? Remember: output 0 is fused; outputs 1-6 are side predictions, all already passed through sigmoid in the bundled model implementations.
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).