AGENT SKILL

segmentation-models

Use Segmentation Models for Keras/TensorFlow image segmentation model construction, losses, metrics, preprocessing, training utilities, and troubleshooting.

License 许可
MIT
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
segmentation-models
license
MIT
metadata
{ "disco-role": "operating" }
description
Use Segmentation Models for Keras/TensorFlow image segmentation model construction, losses, metrics, preprocessing, training utilities, and troubleshooting.
disable-model-invocation
true

02 资源文件 4

03 SKILL.md 正文

Segmentation Models Repo Skill

Use this repo skill when a task asks about the Python package segmentation_models / Segmentation Models: constructing Keras semantic-segmentation models, selecting backbones, configuring preprocessing, choosing segmentation losses/metrics, or assembling small training/evaluation/fine-tuning workflows.

This skill is for using the package as an operating library. If the task is about editing the repository source, packaging releases, or changing tests, use a Python repository maintenance skill instead.

Install and import baseline

Segmentation Models 1.x expects a Keras backend plus its own package dependencies. The package metadata installs keras_applications, image-classifiers, and efficientnet; TensorFlow/Keras itself is chosen separately for the target platform.

pip install segmentation-models
# Install a compatible TensorFlow/Keras backend for the environment.

In modern TensorFlow environments, prefer TensorFlow Keras and set the framework before import:

import os
os.environ.setdefault("SM_FRAMEWORK", "tf.keras")
import segmentation_models as sm

print(sm.__version__)
print(sm.framework())
print(sm.get_available_backbone_names()[:5])

Run scripts/check_environment.py when a task needs a no-data import/framework/backbone smoke check. Add --build-model only when the environment can import TensorFlow/Keras and can build a tiny offline model with encoder_weights=None.

Route map

User task Read
Instantiate Unet, Linknet, FPN, or PSPNet; choose backbone_name, input_shape, classes, activation, encoder_weights; debug shape/backbone/framework constructor errors. sub-skills/model-construction/SKILL.md
Choose IOUScore, FScore, Dice/Jaccard/focal/CE losses; configure class weights/indexes, thresholds, per-image reduction; hand-check metric math. sub-skills/losses-metrics/SKILL.md
Assemble training/evaluation/fine-tuning loops; use get_preprocessing; set image/mask shapes; handle non-RGB data; freeze/unfreeze encoders; add regularization; run synthetic training smoke checks. sub-skills/training-utilities/SKILL.md
Diagnose package-wide install/import/backend/version problems before a workflow-specific route. references/troubleshooting.md
Decide whether this skill is current for a checkout or package release. references/repo-provenance.md

Fast workflow patterns

Binary segmentation model

import os
os.environ.setdefault("SM_FRAMEWORK", "tf.keras")
import segmentation_models as sm

BACKBONE = "resnet34"
preprocess_input = sm.get_preprocessing(BACKBONE)
model = sm.Unet(
    BACKBONE,
    classes=1,
    activation="sigmoid",
    encoder_weights="imagenet",
)
model.compile("Adam", loss=sm.losses.bce_jaccard_loss, metrics=[sm.metrics.iou_score])

Multiclass model

model = sm.FPN(
    "efficientnetb0",
    input_shape=(256, 256, 3),
    classes=4,
    activation="softmax",
    encoder_weights="imagenet",
)
model.compile("Adam", loss=sm.losses.cce_jaccard_loss, metrics=[sm.metrics.IOUScore()])

Offline smoke construction

model = sm.Unet(
    "resnet18",
    input_shape=(32, 32, 3),
    classes=1,
    activation="sigmoid",
    encoder_weights=None,
)

Safety and scope notes

  • encoder_weights="imagenet" may download weights and expects RGB-compatible input. Use encoder_weights=None for offline checks, non-RGB direct inputs, and deterministic smoke tests.
  • The bundled scripts use synthetic data or parser/help checks only; they do not clone datasets, train benchmark models, or require GPU.
  • CUDA/GPU is optional acceleration for real training in this package. CPU TensorFlow/Keras is sufficient for import, model-construction, loss/metric, and tiny training validation.
  • Original notebooks and tests were used as evidence, but runtime guidance here is self-contained; do not require future agents to open or execute files from the original checkout.

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351