segmentation_models_pytorch库学习

 https://qixinbo.info/2020/02/16/kaggle-steel-2/

segmentation_models_pytorch是一个基于PyTorch的图像分割神经网络

这个新集合由俄罗斯的程序员小哥Pavel Yakubovskiy一手打造。
github地址:https://github.com/qubvel/segmentation_models.pytorch
在这里插入图片描述
该库的主要功能是:

  1. 高级API(只需两行即可创建神经网络)

  2. 用于二分类和多类分割的7种模型架构(包括传奇的Unet)

  3. 每种架构有57种可用的编码器

  4. 所有编码器均具有预训练的权重,以实现更快更好的收敛

一、安装

PyPI version:

pip install segmentation-models-pytorch
  • 1

Latest version from source:

pip install git+https://github.com/qubvel/segmentation_models.pytorch
  • 1
二、使用

由于该库是基于PyTorch框架构建的,因此创建的细分模型只是一个PyTorch nn.Module,可以轻松地创建它:

import segmentation_models_pytorch as smp
model = smp.Unet()
  • 1
  • 2

根据任务的不同,您可以通过选择具有更少或更多参数的主干并使用预训练的权重来初始化它来更改网络体系结构:

model = smp.Unet('resnet34', encoder_weights='imagenet')
  • 1

更改模型中输出类的数量:

model = smp.Unet('resnet34', classes=3, activation='softmax')
  • 1

所有模型均具有预训练的编码器,因此您必须按照权重预训练的相同方法准备数据:

from segmentation_models_pytorch.encoders import get_preprocessing_fn
preprocess_input = get_preprocessing_fn('resnet18', pretrained='imagenet')
  • 1
  • 2

更加详细的请见github源码

注,还有其他优秀的库
例如https://github.com/CSAILVision/semantic-segmentation-pytorch
在这里插入图片描述
真的是学无止境啊,先star吧,再继续学习。

参考:
https://baijiahao.baidu.com/s?id=1632513555001646060&wfr=spider&for=pc
https://github.com/qubvel/segmentation_models.pytorch
https://github.com/CSAILVision/semantic-segmentation-pytorch

https://zhuanlan.zhihu.com/p/80688663
(这里面有一个实战项目)

posted @   水木清扬  阅读(1717)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
历史上的今天:
2019-02-22 keras加载模型,单张图像
点击右上角即可分享
微信分享提示