Package: segmentation-sust
Python library with Neural Networks for ImageSegmentation based onPyTorch.The main features of this library are:High level API (just two lines to create neural network)8 models architectures for binary and multi class segmentation (including legendary Unet)99 available encodersAll encoders have pre-trained weights for faster and better convergence📚 Project Documentation 📚VisitRead The Docs Project Pageor read following README to know more about Segmentation Models Pytorch (SMP for short) library📋 Table of contentQuick startExamplesModelsArchitecturesEncodersModels APIInput channelsAuxiliary classification outputDepthInstallationCompetitions won with the libraryContributingCitingLicense⏳ Quick start1. Create your first Segmentation model with SMPSegmentation model is just a PyTorch nn.Module, which can be created as easy as:importsegmentation_sustassmpmodel=smp.Unet(encoder_name="resnet34",# choose encoder, e.g. mobilenet_v2 or efficientnet-b7encoder_weights="imagenet",# use `imagenet` pretreined weights for encoder initializationin_channels=1,# model input channels (1 for grayscale images, 3 for RGB, etc.)classes=3,# model output channels (number of classes in your dataset))seetablewith available model architecturesseetablewith avaliable encoders and its corresponding weights2. Configure data preprocessingAll encoders have pretrained weights. Preparing your data the same way as during weights pretraining may give your better results (higher metric score and faster convergence). But it is relevant only for 1-2-3-channels images andnot necessaryin case you train the whole model, not only decoder.fromsegmentation_sust.encodersimportget_preprocessing_fnpreprocess_input=get_preprocessing_fn('resnet18',pretrained='imagenet')Congratulations! You are done! Now you can train your model with your favorite framework!💡 ExamplesTraining model for cars segmentation on CamVid datasethere.Training SMP model withCatalyst(high-level framework for PyTorch),TTAch(TTA library for PyTorch) andAlbumentations(fast image augmentation library) -here📦 ModelsArchitecturesUnet [paper] [docs]Unet++ [paper] [docs]Linknet [paper] [docs]FPN [paper] [docs]PSPNet [paper] [docs]PAN [paper] [docs]DeepLabV3 [paper] [docs]DeepLabV3+ [paper] [docs]EncodersThe following is a list of supported encoders in the SMP. Select the appropriate family of encoders and click to expand the table and select a specific encoder and its pre-trained weights (encoder_nameandencoder_weightsparameters).ResNetEncoderWeightsParams, Mresnet18imagenet / ssl / swsl11Mresnet34imagenet21Mresnet50imagenet / ssl / swsl23Mresnet101imagenet42Mresnet152imagenet58MResNeXtEncoderWeightsParams, Mresnext50_32x4dimagenet / ssl / swsl22Mresnext101_32x4dssl / swsl42Mresnext101_32x8dimagenet / instagram / ssl / swsl86Mresnext101_32x16dinstagram / ssl / swsl191Mresnext101_32x32dinstagram466Mresnext101_32x48dinstagram826MResNeStEncoderWeightsParams, Mtimm-resnest14dimagenet8Mtimm-resnest26dimagenet15Mtimm-resnest50dimagenet25Mtimm-resnest101eimagenet46Mtimm-resnest200eimagenet68Mtimm-resnest269eimagenet108Mtimm-resnest50d_4s2x40dimagenet28Mtimm-resnest50d_1s4x24dimagenet23MRes2Ne(X)tEncoderWeightsParams, Mtimm-res2net50_26w_4simagenet23Mtimm-res2net101_26w_4simagenet43Mtimm-res2net50_26w_6simagenet35Mtimm-res2net50_26w_8simagenet46Mtimm-res2net50_48w_2simagenet23Mtimm-res2net50_14w_8simagenet23Mtimm-res2next50imagenet22MRegNet(x/y)EncoderWeightsParams, Mtimm-regnetx_002imagenet2Mtimm-regnetx_004imagenet4Mtimm-regnetx_006imagenet5Mtimm-regnetx_008imagenet6Mtimm-regnetx_016imagenet8Mtimm-regnetx_032imagenet14Mtimm-regnetx_040imagenet20Mtimm-regnetx_064imagenet24Mtimm-regnetx_080imagenet37Mtimm-regnetx_120imagenet43Mtimm-regnetx_160imagenet52Mtimm-regnetx_320imagenet105Mtimm-regnety_002imagenet2Mtimm-regnety_004imagenet3Mtimm-regnety_006imagenet5Mtimm-regnety_008imagenet5Mtimm-regnety_016imagenet10Mtimm-regnety_032imagenet17Mtimm-regnety_040imagenet19Mtimm-regnety_064imagenet29Mtimm-regnety_080imagenet37Mtimm-regnety_120imagenet49Mtimm-regnety_160imagenet80Mtimm-regnety_320imagenet141MSE-NetEncoderWeightsParams, Msenet154imagenet113Mse_resnet50imagenet26Mse_resnet101imagenet47Mse_resnet152imagenet64Mse_resnext50_32x4dimagenet25Mse_resnext101_32x4dimagenet46MSK-ResNe(X)tEncoderWeightsParams, Mtimm-skresnet18imagenet11Mtimm-skresnet34imagenet21Mtimm-skresnext50_32x4dimagenet25MDenseNetEncoderWeightsParams, Mdensenet121imagenet6Mdensenet169imagenet12Mdensenet201imagenet18Mdensenet161imagenet26MInceptionEncoderWeightsParams, Minceptionresnetv2imagenet /  imagenet+background54Minceptionv4imagenet /  imagenet+background41Mxceptionimagenet22MEfficientNetEncoderWeightsParams, Mefficientnet-b0imagenet4Mefficientnet-b1imagenet6Mefficientnet-b2imagenet7Mefficientnet-b3imagenet10Mefficientnet-b4imagenet17Mefficientnet-b5imagenet28Mefficientnet-b6imagenet40Mefficientnet-b7imagenet63Mtimm-efficientnet-b0imagenet / advprop / noisy-student4Mtimm-efficientnet-b1imagenet / advprop / noisy-student6Mtimm-efficientnet-b2imagenet / advprop / noisy-student7Mtimm-efficientnet-b3imagenet / advprop / noisy-student10Mtimm-efficientnet-b4imagenet / advprop / noisy-student17Mtimm-efficientnet-b5imagenet / advprop / noisy-student28Mtimm-efficientnet-b6imagenet / advprop / noisy-student40Mtimm-efficientnet-b7imagenet / advprop / noisy-student63Mtimm-efficientnet-b8imagenet / advprop84Mtimm-efficientnet-l2noisy-student474MMobileNetEncoderWeightsParams, Mmobilenet_v2imagenet2MDPNEncoderWeightsParams, Mdpn68imagenet11Mdpn68bimagenet+5k11Mdpn92imagenet+5k34Mdpn98imagenet58Mdpn107imagenet+5k84Mdpn131imagenet76MVGGEncoderWeightsParams, Mvgg11imagenet9Mvgg11_bnimagenet9Mvgg13imagenet9Mvgg13_bnimagenet9Mvgg16imagenet14Mvgg16_bnimagenet14Mvgg19imagenet20Mvgg19_bnimagenet20M*ssl,swsl- semi-supervised and weakly-supervised learning on ImageNet (repo).🔁 Models APImodel.encoder- pretrained backbone to extract features of different spatial resolutionmodel.decoder- depends on models architecture (Unet/Linknet/PSPNet/FPN)model.segmentation_head- last block to produce required number of mask channels (include also optional upsampling and activation)model.classification_head- optional block which create classification head on top of encodermodel.forward(x)- sequentially passxthrough model`s encoder, decoder and segmentation head (and classification head if specified)Input channelsInput channels parameter allow you to create models, which process tensors with arbitrary number of channels.
If you use pretrained weights from imagenet - weights of first convolution will be reused for
1- or 2- channels inputs, for input channels > 4 weights of first convolution will be initialized randomly.model=smp.FPN('resnet34',in_channels=1)mask=model(torch.ones([1,1,64,64]))Auxiliary classification outputAll models supportaux_paramsparameters, which is default set toNone.
Ifaux_params = Nonethan classification auxiliary output is not created, else
model produce not onlymask, but alsolabeloutput with shapeNC.
Classification head consist of GlobalPooling->Dropout(optional)->Linear->Activation(optional) layers, which can be
configured byaux_paramsas follows:aux_params=dict(pooling='avg',# one of 'avg', 'max'dropout=0.5,# dropout ratio, default is Noneactivation='sigmoid',# activation function, default is Noneclasses=4,# define number of output labels)model=smp.Unet('resnet34',classes=4,aux_params=aux_params)mask,label=model(x)DepthDepth parameter specify a number of downsampling operations in encoder, so you can make
your model lighted if specify smallerdepth.model=smp.Unet('resnet34',encoder_depth=4)🛠 InstallationPyPI version:$pipinstallsegmentation-models-pytorchLatest version from source:$pipinstallgit+https://github.com/qubvel/segmentation_models.pytorch🏆 Competitions won with the librarySegmentation Modelspackage is widely used in the image segmentation competitions.Hereyou can find competitions, names of the winners and links to their solutions.🤝 ContributingRun test$dockerbuild-fdocker/Dockerfile.dev-tsmp:dev.&&dockerrun--rmsmp:devpytest-pno:cacheproviderGenerate table$dockerbuild-fdocker/Dockerfile.dev-tsmp:dev.&&dockerrun--rmsmp:devpythonmisc/generate_table.py📝 Citing@misc{Yakubovskiy:2019,
  Author = {Pavel Yakubovskiy},
  Title = {Segmentation Models Pytorch},
  Year = {2020},
  Publisher = {GitHub},
  Journal = {GitHub repository},
  Howpublished = {\url{https://github.com/qubvel/segmentation_models.pytorch}}
}🛡️ LicenseProject is distributed underMIT License