图像分割技术语义分割代码
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