关于segmentation_models的一些总结

首先,此库作用为:基于Tensorflow和Keras框架的用于图像分割的神经网络库。

安装程序为:pip install import segmentation_models

导入程序为:import segmentation_models as sm

作者Github地址:https://github.com/qubvel/segmentation_models

主要的优点有(翻译自作者):

  1.  高级 API(只需两行代码即可创建分割模型)
  2.  用于二进制和多类图像分割的 4 种模型架构(包括Unet)
  3.  每个架构有 25 个可用的骨架
  4.  所有主干都有预训练的权重,以便更快更好地收敛
  5.  常用的分割损失(Jaccard、Dice、Focal)和指标(IoU、F-score)

 创建的分割模型只是 Keras 模型的一个实例,它的构建可以像这样一样简单:

model = sm.Unet()

根据任务,可以通过选择具有更少或更多参数的主干并使用预训练的权重对其进行初始化来更改网络架构:

model = sm.Unet('resnet34', encoder_weights='imagenet')

 更改模型中输出类的数量(根据情况来选择):

# binary segmentation (this parameters are default when you call Unet('resnet34')
model = sm.Unet('resnet34', classes=1, activation='sigmoid')
# multiclass segmentation with non overlapping class masks (your classes + background)
model = sm.Unet('resnet34', classes=3, activation='softmax')
# multiclass segmentation with independent overlapping/non-overlapping class masks
model = sm.Unet('resnet34', classes=3, activation='sigmoid')

更改模型的输入形状:

# if you set input channels not equal to 3, you have to set encoder_weights=None
# how to handle such case with encoder_weights='imagenet' described in docs
model = Unet('resnet34', input_shape=(None, None, 6), encoder_weights=None)

简单的示例:

import segmentation_models as sm

BACKBONE = 'resnet34'
preprocess_input = sm.get_preprocessing(BACKBONE)

# load your data
x_train, y_train, x_val, y_val = load_data(...)

# preprocess input
x_train = preprocess_input(x_train)
x_val = preprocess_input(x_val)

# define model
model = sm.Unet(BACKBONE, encoder_weights='imagenet')
model.compile(
    'Adam',
    loss=sm.losses.bce_jaccard_loss,
    metrics=[sm.metrics.iou_score],
)

# fit model
# if you use data generator use model.fit_generator(...) instead of model.fit(...)
# more about `fit_generator` here: https://keras.io/models/sequential/#fit_generator
model.fit(
   x=x_train,
   y=y_train,
   batch_size=16,
   epochs=100,
   validation_data=(x_val, y_val),
)

后续会介绍一些关于骨架和分割网络的内容!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值