图像分割算法之pspnet的三种训练模型pspnet_50_ADE_20K,pspnet_101_cityscapes,pspnet_101_voc12

1.引用库:https://github.com/divamgupta/image-segmentation-keras
2.依赖项:tensorflow==1.14.1,keras2.0, keras-segmentation
3.main程序读取当前image文件夹下的图像,进行图像分割,然后将结果保存在output下
4.本程序已经将三种模型的输出结果分别保存,并重命名为方法的名字,比如:pspnet_50_ADE_20K,pspnet_101_cityscapes,pspnet_101_voc12

# main.py
import os
import glob
from keras_segmentation.pretrained import pspnet_50_ADE_20K , pspnet_101_cityscapes, pspnet_101_voc12
from keras_segmentation.pretrained import model_from_checkpoint_path
# model = pspnet_50_ADE_20K()
# model = pspnet_101_cityscapes()
model = pspnet_101_voc12()

imgs = glob.glob("image/*")
for img in imgs:
    print(img)
    saves= os.path.join("output","out_"+img[6:])
    print(saves)
    out = model.predict_segmentation(
        inp=img,
        out_fname=saves
    )

5.pretrained.py文件如下:

import keras

from .models.all_models import model_from_name


def model_from_checkpoint_path(model_config, latest_weights):

    model = model_from_name[model_config['model_class']](
        model_config['n_classes'], input_height=model_config['input_height'],
        input_width=model_config['input_width'])
    model.load_weights(latest_weights)
    return model


def resnet_pspnet_VOC12_v0_1():

    model_config = {
        "output_height": 96,
        "input_height": 384,
        "input_width": 576,
        "n_classes": 151,
        "model_class": "resnet50_pspnet",
        "output_width": 144
    }

    REPO_URL = "https://github.com/divamgupta/image-segmentation-keras"
    MODEL_PATH = "pretrained_model_1/r2_voc12_resnetpspnet_384x576.24"
    model_url = "{0}/releases/download/{1}".format(REPO_URL, MODEL_PATH)
    latest_weights = keras.utils.get_file(model_url.split("/")[-1], model_url)

    return model_from_checkpoint_path(model_config, latest_weights)


# pretrained model converted from caffe by Vladkryvoruchko ... thanks !
def pspnet_50_ADE_20K():

    model_config = {
        "input_height": 473,
        "input_width": 473,
        "n_classes": 150,
        "model_class": "pspnet_50",
    }

    model_url = "https://www.dropbox.com/s/" \
                "0uxn14y26jcui4v/pspnet50_ade20k.h5?dl=1"
    latest_weights = keras.utils.get_file("pspnet50_ade20k.h5", model_url)

    return model_from_checkpoint_path(model_config, latest_weights)


def pspnet_101_cityscapes():

    model_config = {
        "input_height": 713,
        "input_width": 713,
        "n_classes": 19,
        "model_class": "pspnet_101",
    }

    model_url = "https://www.dropbox.com/s/" \
                "c17g94n946tpalb/pspnet101_cityscapes.h5?dl=1"
    latest_weights = keras.utils.get_file("pspnet101_cityscapes.h5", model_url)

    return model_from_checkpoint_path(model_config, latest_weights)


def pspnet_101_voc12():

    model_config = {
        "input_height": 473,
        "input_width": 473,
        "n_classes": 21,
        "model_class": "pspnet_101",
    }

    model_url = "https://www.dropbox.com/s/" \
                "uvqj2cjo4b9c5wg/pspnet101_voc2012.h5?dl=1"
    latest_weights = keras.utils.get_file("pspnet101_voc2012.h5", model_url)

    return model_from_checkpoint_path(model_config, latest_weights)
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值