AI攻略:Paddlehub實現人體解析

u_d5610d79507e發表於2020-01-18

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

模型概述

人體解析(Human Parsing)是細粒度的語義分割任務,其旨在識別畫素級別的人類影像的組成部分(例如,身體部位和服裝)。ACE2P透過融合底層特徵,全域性上下文資訊和邊緣細節,端到端地訓練學習人體解析任務。該結構針對Intersection over Union指標進行針對性的最佳化學習,提升準確率。以ACE2P單人人體解析網路為基礎的解決方案在CVPR2019第三屆LIP挑戰賽中贏得了全部三個人體解析任務的第一名。該PaddleHub Module採用ResNet101作為骨幹網路,接受輸入圖片大小為473x473x3。

AI攻略:Paddlehub實現人體解析

API

def segmentation(data)

用於人像分割

引數

data:dict型別,key為 image,str型別;value為待分割的圖片路徑,list型別。

output_dir:生成圖片的儲存路徑,預設為ace2p_output

返回

result:list型別,每個元素為對應輸入圖片的預測結果。預測結果為dict型別,有以下欄位:

origin原輸入圖片路徑

processed分割圖片的路徑。

調色盤

AI攻略:Paddlehub實現人體解析

程式碼與案例

import paddlehub as hub

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

#ace2p

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

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 = "./ace2p_output/body2_processed.png"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-09 07:10:08,251] [    INFO] - Installing ace2p module

2020-01-09 07:10:08,251-INFO: Installing ace2p module

[2020-01-09 07:10:08,270] [    INFO] - Module ace2p already installed in /home/aistudio/.paddlehub/modules/ace2p

2020-01-09 07:10:08,270-INFO: Module ace2p already installed in /home/aistudio/.paddlehub/modules/ace2p

AI攻略:Paddlehub實現人體解析

[2020-01-09 07:10:09,154] [    INFO] - 0 pretrained paramaters loaded by PaddleHub

2020-01-09 07:10:09,154-INFO: 0 pretrained paramaters loaded by PaddleHub

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

AI攻略:Paddlehub實現人體解析

In[4]

import paddlehub as hub

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

#ace2p

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

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 = "./ace2p_output/body1_processed.png"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-09 07:12:05,461] [    INFO] - Installing ace2p module

2020-01-09 07:12:05,461-INFO: Installing ace2p module

[2020-01-09 07:12:05,499] [    INFO] - Module ace2p already installed in /home/aistudio/.paddlehub/modules/ace2p

2020-01-09 07:12:05,499-INFO: Module ace2p already installed in /home/aistudio/.paddlehub/modules/ace2p

AI攻略:Paddlehub實現人體解析

[2020-01-09 07:12:06,441] [    INFO] - 0 pretrained paramaters loaded by PaddleHub

2020-01-09 07:12:06,441-INFO: 0 pretrained paramaters loaded by PaddleHub

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

AI攻略:Paddlehub實現人體解析

In[7]

import paddlehub as hub

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

#ace2p

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

test_img_path = "./body3.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 = "./ace2p_output/body3_processed.png"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-09 07:13:10,483] [    INFO] - Installing ace2p module

2020-01-09 07:13:10,483-INFO: Installing ace2p module

[2020-01-09 07:13:10,502] [    INFO] - Module ace2p already installed in /home/aistudio/.paddlehub/modules/ace2p

2020-01-09 07:13:10,502-INFO: Module ace2p already installed in /home/aistudio/.paddlehub/modules/ace2p

AI攻略:Paddlehub實現人體解析

[2020-01-09 07:13:11,395] [    INFO] - 0 pretrained paramaters loaded by PaddleHub

2020-01-09 07:13:11,395-INFO: 0 pretrained paramaters loaded by PaddleHub

{'origin': './body3.jpg', 'processed': 'ace2p_output/body3_processed.png'}

AI攻略:Paddlehub實現人體解析


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

相關文章