segmentation-models-pytorch
Route segmentation_models_pytorch tasks for semantic segmentation model creation, encoders, preprocessing, losses, metrics, export, and repository maintenance.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- segmentation-models-pytorch
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Route segmentation_models_pytorch tasks for semantic segmentation model creation, encoders, preprocessing, losses, metrics, export, and repository maintenance.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/package-overview.md3.1 KB
- 参考文档references/repo-provenance.md1.7 KB
- 参考文档references/repo-routing-metadata.json359 B
- 参考文档references/troubleshooting.md3.7 KB
- 脚本scripts/check_install.py3.6 KB
03 SKILL.md 正文
Segmentation Models PyTorch
Use this repo skill when the task involves segmentation_models_pytorch (SMP), a PyTorch semantic segmentation library with high-level model constructors, pretrained encoders, segmentation losses/metrics, and save/load/export workflows.
Start Here
- Read Package Overview for the public API surfaces, dependency expectations, and how the sub-skills fit together.
- Read Repository Provenance before deciding whether this skill is current for a checkout or package version.
- Read Troubleshooting for cross-cutting install/import, PyTorch, Hugging Face Hub, optional dependency, and routing failures.
- Run check_install.py when an environment may not have SMP, PyTorch, timm, Hugging Face Hub, or CUDA visibility set up correctly.
Route By Task
- Use model-building to create or debug
Unet,FPN,DeepLabV3Plus,Segformer,DPT,smp.create_model, tensor shapes, auxiliary heads, or encoder freeze/unfreeze behavior. - Use encoders-preprocessing to choose
encoder_name, list supported encoders, migrate deprecatedtimm-names, usetu-timm universal encoders, configure pretrained weights, or get preprocessing mean/std functions. - Use training-evaluation for
DiceLoss,JaccardLoss,TverskyLoss,FocalLoss, binary/multiclass/multilabel target shapes,smp.metrics.get_stats, IoU/F1/accuracy, or safe training/evaluation loops. - Use model-export for
save_pretrained,smp.from_pretrained, changed class counts withstrict=False, Hugging Face Hub sharing, ONNX, TorchScript,torch.export, ortorch.compilereadiness. - Use repo-development only when the user is editing an SMP checkout: adding models/encoders/losses, updating docs tables, selecting focused tests, or maintaining package metadata.
Quick Install And Import Check
SMP is published as segmentation-models-pytorch on PyPI and imports as segmentation_models_pytorch:
pip install -U segmentation-models-pytorch
python - <<'PY'
import segmentation_models_pytorch as smp
print(smp.__version__)
print(sorted(smp.MODEL_ARCHITECTURES_MAPPING))
PY
For local repo work, install the current checkout in editable mode with its runtime dependencies. Add test or docs extras only when the task actually needs tests or documentation builds.
Common Public APIs
- Model constructors:
smp.Unet,smp.UnetPlusPlus,smp.MAnet,smp.Linknet,smp.FPN,smp.PSPNet,smp.PAN,smp.DeepLabV3,smp.DeepLabV3Plus,smp.UPerNet,smp.Segformer,smp.DPT. - Generic model factory:
smp.create_model(arch, encoder_name="resnet34", encoder_weights="imagenet", in_channels=3, classes=1, **kwargs). - Encoder utilities:
smp.encoders.get_encoder_names(),get_encoder(...),get_preprocessing_params(...), andget_preprocessing_fn(...). - Losses and modes:
smp.losses.BINARY_MODE,MULTICLASS_MODE,MULTILABEL_MODE, plus Dice, Jaccard, Tversky, Focal, Lovasz, SoftBCE, SoftCE, and MCC losses. - Metrics:
smp.metrics.get_stats(...)followed byiou_score,f1_score,accuracy,precision,recall, or related rates. - Persistence:
model.save_pretrained(...)andsmp.from_pretrained(...)for local directories or Hub repos when network and credentials are available.
Safe Defaults
- Prefer
encoder_weights=Nonefor offline smoke tests to avoid downloading pretrained weights. - Use small tensor sizes such as
64x64or128x128for shape checks; do not run notebook-scale training or dataset downloads unless the user explicitly requests them. - Use
classes=1for binary logits,classes=Nfor multiclass/multilabel logits, and choose the matching loss/metric mode in training-evaluation. - Treat Hugging Face Hub pushes, pretrained checkpoint downloads, ONNX export, and long training examples as optional/networked workflows with explicit prerequisites.
When To Refresh This Skill
Refresh this skill when SMP changes model constructors, architecture registry names, encoder registry behavior, pretrained weight handling, loss/metric signatures, save/load APIs, export compatibility, package dependencies, or maintainer test conventions. Use Repository Provenance to compare the current checkout against the generation baseline.
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).