PaddleHub可以便捷地獲取PaddlePaddle生態(tài)下的預(yù)訓(xùn)練模型捎泻,完成模型的管理和一鍵預(yù)測(cè)秧均。配合使用Fine-tune API,可以基于大規(guī)模預(yù)訓(xùn)練模型快速完成遷移學(xué)習(xí),讓預(yù)訓(xùn)練模型能更好地服務(wù)于用戶特定場(chǎng)景的應(yīng)用竟趾。
模型概述
人體解析(Human Parsing)是細(xì)粒度的語(yǔ)義分割任務(wù)顾瞻,其旨在識(shí)別像素級(jí)別的人類圖像的組成部分(例如泼疑,身體部位和服裝)。ACE2P通過(guò)融合底層特征荷荤,全局上下文信息和邊緣細(xì)節(jié)退渗,端到端地訓(xùn)練學(xué)習(xí)人體解析任務(wù)。該結(jié)構(gòu)針對(duì)Intersection over Union指標(biāo)進(jìn)行針對(duì)性的優(yōu)化學(xué)習(xí)蕴纳,提升準(zhǔn)確率会油。以ACE2P單人人體解析網(wǎng)絡(luò)為基礎(chǔ)的解決方案在CVPR2019第三屆LIP挑戰(zhàn)賽中贏得了全部三個(gè)人體解析任務(wù)的第一名。該P(yáng)addleHub Module采用ResNet101作為骨干網(wǎng)絡(luò)古毛,接受輸入圖片大小為473x473x3翻翩。
?
API
def segmentation(data)
用于人像分割
參數(shù)
data:dict類型都许,key為image,str類型嫂冻;value為待分割的圖片路徑胶征,list類型。
output_dir:生成圖片的保存路徑桨仿,默認(rèn)為ace2p_output
返回
result:list類型睛低,每個(gè)元素為對(duì)應(yīng)輸入圖片的預(yù)測(cè)結(jié)果。預(yù)測(cè)結(jié)果為dict類型服傍,有以下字段:
origin原輸入圖片路徑
processed分割圖片的路徑钱雷。
調(diào)色板
?
代碼與案例
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"
# 預(yù)測(cè)結(jié)果展示
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"
# 預(yù)測(cè)結(jié)果展示
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"
# 預(yù)測(cè)結(jié)果展示
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'}
?