PaddleHub能夠便捷地獲取PaddlePaddle生態下的預訓練模型,完成模型的管理和一鍵預測。配合使用Fine-tune API,能夠基於大規模預訓練模型快速完成遷移學習,讓預訓練模型能更好地服務於用戶特定場景的應用。網絡
模型概述學習
人體解析(Human Parsing)是細粒度的語義分割任務,其旨在識別像素級別的人類圖像的組成部分(例如,身體部位和服裝)。ACE2P經過融合底層特徵,全局上下文信息和邊緣細節,端到端地訓練學習人體解析任務。該結構針對Intersection over Union指標進行鍼對性的優化學習,提高準確率。以ACE2P單人人體解析網絡爲基礎的解決方案在CVPR2019第三屆LIP挑戰賽中贏得了所有三我的體解析任務的第一名。該PaddleHub Module採用ResNet101做爲骨幹網絡,接受輸入圖片大小爲473x473x3。優化
APIblog
def segmentation(data)圖片
用於人像分割input
參數io
data:dict類型,key爲image,str類型;value爲待分割的圖片路徑,list類型。test
output_dir:生成圖片的保存路徑,默認爲ace2p_outputimport
返回基礎
result:list類型,每一個元素爲對應輸入圖片的預測結果。預測結果爲dict類型,有如下字段:
origin原輸入圖片路徑
processed分割圖片的路徑。
調色板
代碼與案例
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
[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'}
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
[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'}
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
[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'}