百度AI攻略:Paddlehub實現影像分割

u_d5610d79507e發表於2020-01-18

PaddleHub可以便捷地獲取PaddlePaddle生態下的預訓練模型,完成模型的管理和一鍵預測。配合使用Fine-tune API,可以基於大規模預訓練模型快速完成遷移學習,讓預訓練模型能更好地服務於使用者特定場景的應用。

模型概述:

模型概述 DeepLabv3+ 是Google DeepLab語義分割系列網路的最新作,其前作有 DeepLabv1,DeepLabv2, DeepLabv3。在最新作中,作者透過encoder-decoder進行多尺度資訊的融合,同時保留了原來的空洞卷積和ASSP層, 其骨幹網路使用了Xception模型,提高了語義分割的健壯性和執行速率,在 PASCAL VOC 2012 dataset取得新的state-of-art performance。該PaddleHub Module使用百度自建資料集進行訓練,可用於人像分割,支援任意大小的圖片輸入。

程式碼及效果示例:

import paddlehub as hub

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

#deeplabv3p_xception65_humanseg

module = hub.Module(name="deeplabv3p_xception65_humanseg")

test_img_path = "./body2.jpg"

# 預測結果展示

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

# set input dict

input_dict = {"image": [test_img_path]}

# execute predict and print the result

results = module.segmentation(data=input_dict)

for result in results:

    print(result)

test_img_path = "./humanseg_output/body2.png"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-07 06:03:45,652] [    INFO] - Installing deeplabv3p_xception65_humanseg module

2020-01-07 06:03:45,652-INFO: Installing deeplabv3p_xception65_humanseg module

[2020-01-07 06:03:45,692] [    INFO] - Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg

2020-01-07 06:03:45,692-INFO: Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg

百度AI攻略:Paddlehub實現影像分割

[2020-01-07 06:03:46,479] [    INFO] - 0 pretrained paramaters loaded by PaddleHub

2020-01-07 06:03:46,479-INFO: 0 pretrained paramaters loaded by PaddleHub

{'origin': './body2.jpg', 'processed': 'humanseg_output/body2.png'}

百度AI攻略:Paddlehub實現影像分割

In[5]

#deeplabv3p_xception65_humanseg

module = hub.Module(name="deeplabv3p_xception65_humanseg")

test_img_path = "./body1.jpg"

# 預測結果展示

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

# set input dict

input_dict = {"image": [test_img_path]}

# execute predict and print the result

results = module.segmentation(data=input_dict)

for result in results:

    print(result)

test_img_path = "./humanseg_output/body1.png"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-07 06:04:10,459] [    INFO] - Installing deeplabv3p_xception65_humanseg module

2020-01-07 06:04:10,459-INFO: Installing deeplabv3p_xception65_humanseg module

[2020-01-07 06:04:10,476] [    INFO] - Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg

2020-01-07 06:04:10,476-INFO: Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg

百度AI攻略:Paddlehub實現影像分割

[2020-01-07 06:04:11,422] [    INFO] - 0 pretrained paramaters loaded by PaddleHub

2020-01-07 06:04:11,422-INFO: 0 pretrained paramaters loaded by PaddleHub

{'origin': './body1.jpg', 'processed': 'humanseg_output/body1.png'}

百度AI攻略:Paddlehub實現影像分割


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69922494/viewspace-2673937/,如需轉載,請註明出處,否則將追究法律責任。

相關文章