{"library":"segmentation-models-pytorch","title":"Segmentation Models PyTorch","description":"Segmentation Models PyTorch (SMP) is a Python library offering a high-level API for various neural network architectures, pre-trained backbones, losses, and metrics for image semantic segmentation. It supports 12 encoder-decoder architectures and over 800 pre-trained convolutional and transformer-based encoders, leveraging `timm` for a vast selection. The library focuses on simplicity, fast convergence, and compatibility with PyTorch's `torch.jit.script`, `torch.compile`, and `torch.export` features. It is currently at version 0.5.0 and maintains an active release cadence with frequent updates and new model integrations.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install segmentation-models-pytorch"],"cli":null},"imports":["import segmentation_models_pytorch as smp","model = smp.Unet(...)","from segmentation_models_pytorch.encoders import get_preprocessing_fn"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import torch\nimport segmentation_models_pytorch as smp\nfrom segmentation_models_pytorch.encoders import get_preprocessing_fn\n\n# 1. Create segmentation model\nmodel = smp.Unet(\n    encoder_name=\"resnet34\",          # choose encoder backbone\n    encoder_weights=\"imagenet\",      # use `imagenet` pre-trained weights\n    in_channels=3,                   # model input channels (3 for RGB)\n    classes=1,                       # model output channels (number of classes)\n    activation='sigmoid'             # activation function for binary segmentation\n)\n\n# 2. Configure data preprocessing (important for pre-trained encoders)\npreprocess_input = get_preprocessing_fn('resnet34', pretrained='imagenet')\n\n# Example usage:\n# Dummy input image (batch_size=1, channels=3, height=256, width=256)\nimage = torch.randn(1, 3, 256, 256)\n\n# Apply preprocessing (e.g., normalization)\ninput_tensor = preprocess_input(image)\n\n# Forward pass\nmodel.eval()\nwith torch.no_grad():\n    predicted_mask = model(input_tensor)\n\nprint(f\"Model output shape: {predicted_mask.shape}\")","lang":"python","description":"This quickstart demonstrates how to instantiate a U-Net model with a pre-trained ResNet34 encoder, configure input and output channels, and set an activation function. It also shows how to obtain and apply the correct preprocessing function required for models with pre-trained backbones to ensure optimal performance.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.5.0","pypi_latest":"0.5.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":90,"avg_install_s":70.5,"avg_import_s":14.47,"wheel_type":"sdist"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"19.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":80.6,"import_time_s":12.45,"mem_mb":151.5,"disk_size":"4.8G"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"21.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":74.4,"import_time_s":16.14,"mem_mb":174.3,"disk_size":"4.9G"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":65.6,"import_time_s":15.2,"mem_mb":169.5,"disk_size":"4.8G"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":61.6,"import_time_s":14.11,"mem_mb":171.2,"disk_size":"4.8G"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"segmentation-models-pytorch","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"19.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"segmentation-models-pytorch","exit_code":1,"wheel_type":null,"failure_reason":"timeout","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}