当前位置:网站首页>语义分割模型库segmentation_models_pytorch的详细使用介绍
语义分割模型库segmentation_models_pytorch的详细使用介绍
2022-07-07 22:44:00 【万里鹏程转瞬至】
segmentation_models_pytorch(后文简称smp)是一个用于语义分割的高级模型库,支持9种语义分割网络,400多座编码器,本来对这只支持个别网络的模型库博主是不感兴趣的。但是,在查看到好几个竞赛的top方案都是使用unet++(efficientnet做编码器),博主心动了。如果想要使用更多更全的语义分割模型还是推荐使用MMSegmentation,把MMSegmentation作为语义分割模型库使用可以参考pytorch 24 把MMSegmentation的作为pytorch的语义分割模型库使用(已实现模型的训练与部署)_万里鹏程转瞬至的博客-CSDN博客_mmsegmentation 使用MMSegmentation是商汤科技推出的语义分割库套件,属于 OpenMMLab 项目的一部分,里面有很多的语义分割模型。为什么博主会有这样的骚操作想法呢?原因有二,第一点:MMSegmentation的封装太完善了,作为一个依赖于pytorch的模型库在训练上却不一样,用户的自由发挥空间很小(比如自定义loss、自定义学习率调度器、自定义数据加载器,啥都要重新学),这让博主很难接受;第二点:github上给出了的其他pytorch模型库太拉胯了,支持的模型数量有限,大多只支持2020年以前的模型,这对https://hpg123.blog.csdn.net/article/details/124459439回到正题,接下来描述smp的使用与构造。smp的项目地址为:https://github.com/qubvel/segmentation_models.pytorch
安装smp:
pip install segmentation-models-pytorch
1、基本介绍
9种模型架构(包括传奇的Unet):
- Unet [paper] [docs]
- Unet++ [paper] [docs]
- MAnet [paper] [docs]
- Linknet [paper] [docs]
- FPN [paper] [docs]
- PSPNet [paper] [docs]
- PAN [paper] [docs]
- DeepLabV3 [paper] [docs]
- DeepLabV3+ [paper] [docs]
113个可用编码器(以及来自timm的400多个编码器,所有编码器都具有预先训练的权重,以更快更好地收敛):主要为以下网络的多种版本
ResNet
ResNeXt
ResNeSt
Res2Ne(X)t
RegNet(x/y)
GERNet
SE-Net
SK-ResNe(X)t
DenseNet
Inception
EfficientNet
MobileNet
DPN
VGG
训练常规的常用的损失:支持的loss如下所示(在segmentation_models_pytorch.losses中)
from .jaccard import JaccardLoss
from .dice import DiceLoss
from .focal import FocalLoss
from .lovasz import LovaszLoss
from .soft_bce import SoftBCEWithLogitsLoss
from .soft_ce import SoftCrossEntropyLoss
from .tversky import TverskyLoss
from .mcc import MCCLoss训练常规的常用的指标:在segmentation_models_pytorch.metrics中
from .functional import (
get_stats,
fbeta_score,
f1_score,
iou_score,
accuracy,
precision,
recall,
sensitivity,
specificity,
balanced_accuracy,
positive_predictive_value,
negative_predictive_value,
false_negative_rate,
false_positive_rate,
false_discovery_rate,
false_omission_rate,
positive_likelihood_ratio,
negative_likelihood_ratio,
)2、模型的构建
smp中模型的构建十分便捷,输入解码器类型,权重类型,输入通道数、输出通道数即可。
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)
)但是有的时候,需要对网络结构进行修改,可以指定更为详细的参数(如网络的深度,是否需要辅助头【这里默认的辅助头都是分类头】)。需要注意的是,在unet网络中编码器深度与解码器的stage个数必须相同(stage中的filter num可以按情况修改)

3、模型的具体结构
在smp中,所有的模型都具备以下结构(encoder,decoder和segmentation_head)。encoder是通过传参控制,decoder由具体的model类确定(所有smp模型decoder的输出都是一个tensor,不存在list【如pspnet的多尺度特征,在decoder输出前用conv进行了融合】),segmentation_head由传入的classes确定(只是一个简单的conv层)

所有smp模型的forward流程都如下图所示

边栏推荐
- The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log
- STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
- Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
- 【笔记】常见组合滤波电路
- 华泰证券官方网站开户安全吗?
- SQL knowledge summary 004: Postgres terminal command summary
- A brief history of information by James Gleick
- Solution to the problem of unserialize3 in the advanced web area of the attack and defense world
- 【编程题】【Scratch二级】2019.09 绘制雪花图案
- Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
猜你喜欢

Smart regulation enters the market, where will meituan and other Internet service platforms go

51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
![[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game](/img/81/c84432a7d7c2fe8ef377d8c13991d6.png)
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game

Development of a horse tourism website (realization of login, registration and exit function)

【GO记录】从零开始GO语言——用GO语言做一个示波器(一)GO语言基础

他们齐聚 2022 ECUG Con,只为「中国技术力量」

After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?

Trust orbtk development issues 2022

华为交换机S5735S-L24T4S-QA2无法telnet远程访问

Kubernetes Static Pod (静态Pod)
随机推荐
Installation and configuration of sublime Text3
Introduction knowledge system of Web front-end engineers
The underlying principles and templates of new and delete
RPA云电脑,让RPA开箱即用算力无限?
5G NR 系统消息
paddle入门-使用LeNet在MNIST实现图像分类方法一
Reentrantlock fair lock source code Chapter 0
关于组织2021-2022全国青少年电子信息智能创新大赛西南赛区(四川)复赛的通知
paddle一个由三个卷积层组成的网络完成cifar10数据集的图像分类任务
SQL knowledge summary 004: Postgres terminal command summary
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
paddle入门-使用LeNet在MNIST实现图像分类方法二
After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
Single machine high concurrency model design
Visual Studio Deployment Project - Create shortcut to deployed executable
接口测试要测试什么?
Linkedblockingqueue source code analysis - add and delete
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
What is load balancing? How does DNS achieve load balancing?
STM32F1与STM32CubeIDE编程实例-旋转编码器驱动