█

AI/TLDR

मुझे पिलाएं कॉफ़ी
मुझे एक कॉफ़ी पिलाएँ

Segmentation Models PyTorch

सैकड़ों pretrained encoders वाले image segmentation architectures, एक model के लिए बस दो लाइनें

Vision & Understandingओपन सोर्स
भाषा
Python
लाइसेंस
MIT
$pip install segmentation-models-pytorch
संक्षेप में

Segmentation Models PyTorch क्या है?

Segmentation Models PyTorch सैकड़ों pretrained encoders वाले image segmentation architectures, एक model के लिए बस दो लाइनें. यह Multimodal Generation टूल्स की Vision & Understanding श्रेणी में आता है; ओपन सोर्स है, Python में लिखा गया है और MIT लाइसेंस के तहत है। शुरू करने के लिए: pyPI से install करें.

सारांश

Segmentation Models PyTorch — छोटे में SMP — एक Python लाइब्रेरी है जो दो आपस में बदले जा सकने वाले हिस्सों से semantic-segmentation नेटवर्क बनाती है: एक decoder architecture और एक pretrained encoder। Model एक सादा `torch.nn.Module` होता है, जो एक ही call में बन जाता है, इसलिए यह किसी भी training loop, Lightning module या framework में आसानी से फिट हो जाता है, बिना इसके कि आपको कोई trainer अपनाना पड़े।

यह लाइब्रेरी 12 encoder-decoder architectures — Unet, Unet++, MAnet, Linknet, Segformer, DPT और अन्य — के साथ आती है, और convolution-based व transformer-based 800 से ज़्यादा pretrained encoders देती है, जिनमें पूरा timm catalogue भी शामिल है। Models के साथ यह वे training हिस्से भी देती है जो आमतौर पर प्रोजेक्ट्स के बीच copy-paste किए जाते हैं: Dice, Jaccard और Tversky losses, standard segmentation metrics, और एक preprocessing helper जो हर encoder के pretraining statistics से मेल खाता है।

SMP MIT लाइसेंस वाली है और research व competition दोनों के लिए बनाई गई है — repository में segmentation competitions की एक hall-of-fame page है, जिन्हें इसके साथ जीता गया था। Models ONNX-export friendly हैं और torch script, trace और compile के साथ काम करते हैं, और trained weights को Hugging Face Hub पर save या वहां से load किया जा सकता है। इसके लिए PyTorch 1.9+ और Python 3.9+ चाहिए।

यह क्या करता है

  • 12 encoder-decoder architectures: Unet, Unet++, MAnet, Linknet, Segformer, DPT और अन्य
  • 800+ pretrained encoders, convolutional और transformer-based, timm backbones सहित
  • दो लाइनों में model बनाना — नतीजा एक सामान्य `torch.nn.Module` है, framework-agnostic
  • Segmentation losses (Dice, Jaccard, Tversky) और metrics training routines के लिए साथ में मिलते हैं
  • Preprocessing helper जो हर encoder की pretraining normalisation को दोहराता है
  • ONNX export के साथ torch script / trace / compile सपोर्ट, और Hugging Face Hub के जरिए save/load

शुरू करें

SMP एक लाइब्रेरी है, framework नहीं: इसे install करें, एक model बनाएं, और उसे जैसे भी आप पहले से train करते हैं वैसे train करें। नीचे के सभी snippets project के README से लिए गए हैं।

PyPI से install करें

प्रकाशित package name में dashes होते हैं; import name में underscores होते हैं।

bashbash
pip install segmentation-models-pytorch

या GitHub से नवीनतम version install करें

जब आपको ऐसा fix चाहिए जो main पर आ चुका है पर अभी release नहीं हुआ है, तब git install इस्तेमाल करें।

bashbash
pip install git+https://github.com/qubvel/segmentation_models.pytorch

अपना पहला model बनाएं

एक architecture, एक encoder और उसके pretrained weights चुनें; input channels और classes की संख्या तय करें।

pythonpython
import segmentation_models_pytorch as smp

model = smp.Unet(
    encoder_name="resnet34",        # choose encoder, e.g. mobilenet_v2 or efficientnet-b7
    encoder_weights="imagenet",     # use `imagenet` pre-trained weights for encoder initialization
    in_channels=1,                  # model input channels (1 for gray-scale images, 3 for RGB, etc.)
    classes=3,                      # model output channels (number of classes in your dataset)
)

Encoder का preprocessing मिलाएं

डेटा को उसी तरीके से तैयार करना जिससे encoder को pretrain किया गया था, आमतौर पर तेज़ converge होता है और बेहतर score देता है। अगर आप सिर्फ decoder नहीं, पूरा network train कर रहे हैं तो यह ज़रूरी नहीं है।

pythonpython
from segmentation_models_pytorch.encoders import get_preprocessing_fn

preprocess_input = get_preprocessing_fn('resnet18', pretrained='imagenet')

इसे अपने loop से train करें

यहां से model एक standard PyTorch module है — इसे अपने पसंदीदा framework से train करें। Repository के examples folder में binary, multiclass और pretrained-inference workflows के लिए चलने योग्य notebooks हैं।

टेक्स्टटेक्स्ट
https://smp.readthedocs.io/

कमांड और कोड प्रोजेक्ट के अपने दस्तावेज़ों से लिए गए हैं — हमेशा जांचें आधिकारिक repo ताज़ा जानकारी के लिए।

कब इस्तेमाल करें

  • जब आपको Unet को दोबारा implement करने के बजाय आज ही चलने वाला segmentation baseline चाहिए, तब इसे चुनें
  • Encoders को आज़माने के लिए इसका इस्तेमाल करें — `encoder_name` बदलें और बाकी pipeline वैसा ही रहने दें
  • जब खुद से लिखे गए losses और metrics की जगह परखे हुए segmentation losses और metrics चाहिए, तब इसे चुनें
  • जब trained model को ONNX या torch.compile के जरिए Python से बाहर ले जाना हो, तब इसे चुनें

How Segmentation Models PyTorch compares

Segmentation Models PyTorch alongside other open-source vision & understanding tools AI/TLDR tracks, ranked by GitHub stars.

टूलस्टारयह क्या करता है
PaddleOCR★ 93.6kइमेज में टेक्स्ट खोजें और पहचानें, और 100+ भाषाओं में दस्तावेज़ पार्स करें
OpenCV★ 91.8kलंबे समय से चल रही ओपन सोर्स कंप्यूटर विज़न लाइब्रेरी — इमेज और वीडियो प्रोसेसिंग, कैमरा ज्योमेट्री और वर्शन 5 से एक नया लिखा गया neural-network इंजन, जो VLMs समेत ONNX मॉडल चलाता है
Ultralytics YOLO★ 63.9kरियल-टाइम डिटेक्शन, सेगमेंटेशन और ट्रैकिंग के लिए YOLO मॉडल ट्रेन और चलाएँ
YOLOv5★ 58.3kYOLOv5 डिटेक्शन, सेगमेंटेशन और क्लासिफ़िकेशन मॉडल के पीछे का स्क्रिप्ट-आधारित PyTorch रेपो
Supervision★ 51.8kकंप्यूटर विज़न detections को प्रोसेस और विज़ुअलाइज़ करने के लिए मॉडल-एग्नॉस्टिक Python टूलकिट
MediaPipe★ 38kAndroid, iOS, web, desktop और edge पर विज़न, टेक्स्ट और ऑडियो के लिए डिवाइस पर चलने वाली ML पाइपलाइन
MMDetection★ 33.1kPyTorch के लिए ऑब्जेक्ट डिटेक्शन और सेगमेंटेशन टूलबॉक्स, जिसमें बड़ा मॉडल ज़ू है
Segmentation Models PyTorch★ 11.8kसैकड़ों pretrained encoders वाले image segmentation architectures, एक model के लिए बस दो लाइनें