簡單粗暴,5行代碼,快速實現圖像分割 [Python+PixelLib+opencv+Tensorflow]
簡單粗暴,5行代碼,快速實現圖像分割 [Python+PixelLib+opencv+Tensorflow]
資料來源: https://mp.weixin.qq.com/s/IUm0BPR8rUC0-A3cfrrOyQ
01.安裝環境
pip3 install tensorflow pip3 install pillow pip3 install opencv-python pip3 install scikit-image pip3 install pixellib
Code(01):
import pixellib from pixellib.semantic import semantic_segmentation segment_image = semantic_segmentation() segment_image.load_pascalvoc_model(“deeplabv3_xception_tf_dim_ordering_tf_kernels.h5”) segment_image.segmentAsPascalvoc(“sample1.jpg”, output_image_name = “image_new.jpg”)
Code(02):
import pixellib from pixellib.semantic import semantic_segmentation import time segment_image = semantic_segmentation() segment_image.load_pascalvoc_model(“pascal.h5”) start = time.time() segment_image.segmentAsPascalvoc(“sample1.jpg”, output_image_name= “image_new.jpg”) end = time.time() print(f”Inference Time: {end-start:.2f}seconds”)
Code(03):
import pixellib from pixellib.instance import instance_segmentation segment_image = instance_segmentation() segment_image.load_model(“mask_rcnn_coco.h5”) segment_image.segmentImage(“sample2.jpg”, output_image_name = “image_new.jpg”)
Code(04):
import pixellib from pixellib.instance import instance_segmentation import time segment_image = instance_segmentation() segment_image.load_model(“mask_rcnn_coco.h5”) start = time.time() segment_image.segmentImage(“former.jpg”, output_image_name= “image_new.jpg”) end = time.time() print(f”Inference Time: {end-start:.2f}seconds”)
相關網址:
PixelLib 項目地址:https://github.com/ayoolafenwa/PixelLib
xception模型下載地址:https://github.com/bonlime/keras-deeplab-v3-plus/releases/download/1.1/deeplabv3_xception_tf_dim_ordering_tf_kernels.h5
Mask RCNN模型下載地址:https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5