图像分割技术语义分割代码_用5行代码对150类对象进行语义分割

图像分割技术语义分割代码

It is now possible to perform segmentation on 150 classes of objects using ade20k model with PixelLib. Ade20k model is a deeplabv3+ model trained on ade20k dataset, a dataset with 150 classes of objects. Thanks to tensorflow deeplab’s model zoo, I extracted ade20k model from its tensorflow model checkpoint.

现在可以使用带有PixelLib的ade20k模型对150类对象进行分割。 Ade20k模型是在ade20k数据集上训练的deeplabv3 +模型,该数据集包含150类对象。 感谢tensorflow deeplab的模型动物园,我从其tensorflow模型检查点提取了ade20k模型。

Install the latest version tensorflow (tensorflow 2.0) with:

使用以下命令安装最新版本的tensorflow(tensorflow 2.0):

  • pip3 install tensorflow

    pip3安装tensorflow

Install Pixellib:

安装Pixellib:

  • pip3 install pixellib — upgrade

    pip3 install pixellib —升级

Implementation of Semantic Segmentation with PixelLib:

使用PixelLib实现语义分割:

The code to implement semantic segmentation with deeplabv3+ model is trained on ade20k dataset.

在ade20k数据集上训练了使用deeplabv3 +模型实现语义分割的代码。

import pixellib
from pixellib.semantic import semantic_segmentation


segment_image = semantic_segmentation()
segment_image.load_ade20k_model("deeplabv3_xception65_ade20k.h5")
segment_image.segmentAsAde20k("path_to_image", output_image_name= "path_to_output_image")

We shall observe each line of code:

我们将观察每一行代码:

import pixellib
from pixellib.semantic import semantic_segmentation segment_image = semantic_segmentation()

The class for performing semantic segmentation is imported from pixelLib and we created an instance of the class.

用于执行语义分割的类是从pixelLib导入的,我们创建了该类的实例。

segment_image.load_ade20k_model(“deeplabv3_xception65_ade20k.h5”)

In the code above we loaded the xception model trained on ade20k for segmenting objects. The model can be downloaded from here.

在上面的代码中,我们加载了在ade20k上训练的用于分割对象的Xception模型。 该模型可从此处下载。

segment_image.segmentAsAde20k(“path_to_image”, output_image_name = “path_to_output_image)

We loaded the function to perform segmentation on an image. The function takes two parameters…

我们加载了该功能以对图像进行分割。 该函数有两个参数...

  • path_to_image:- this is the path to the image to be segmented.

    path_to_image:-这是要分割的图像的路径。

  • output_image_name:- this is the path to save the segmented image. It will be saved in your current working directory.

    output_image_name:-这是保存分割图像的路径。 它将保存在您当前的工作目录中。

Sample.jpg

Sample.jpg

Image for post
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值