PaddleHub可以便捷地获取PaddlePaddle生态下的预训练模型,完成模型的管理和一键预测。配合使用Fine-tune API,可以基于大规模预训练模型快速完成迁移学习,让预训练模型能更好地服务于用户特定场景的应用。
模型概述
人体解析(Human Parsing)是细粒度的语义分割任务,其旨在识别像素级别的人类图像的组成部分(例如,身体部位和服装)。ACE2P通过融合底层特征,全局上下文信息和边缘细节,端到端地训练学习人体解析任务。该结构针对Intersection over Union指标进行针对性的优化学习,提升准确率。以ACE2P单人人体解析网络为基础的解决方案在CVPR2019第三届LIP挑战赛中赢得了全部三个人体解析任务的第一名。该PaddleHub Module采用ResNet101作为骨干网络,接受输入图片大小为473x473x3。
![d97c090bbbc01d4b2a9249ea36458ec8.png](https://i-blog.csdnimg.cn/blog_migrate/b99099a8a0307fe60276e22f0ccb873e.jpeg)
API
def segmentation(data)
用于人像分割
参数
data:dict类型,key为image,str类型;value为待分割的图片路径,list类型。
output_dir:生成图片的保存路径,默认为ace2p_output
返回
result:list类型,每个元素为对应输入图片的预测结果。预测结果为dict类型,有以下字段:
origin原输入图片路径
processed分割图片的路径。
调色板
![70ba91bc6fc212944a4e2a099f295de1.png](https://i-blog.csdnimg.cn/blog_migrate/f6655b48fca98e4faa888f9299b9cc60.jpeg)
代码与案例
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
![1f966ba9f4f10a48c739cbc5878858d3.png](https://i-blog.csdnimg.cn/blog_migrate/62c60bceaffa5d617d9f15d50b5d6a30.jpeg)
[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'}
![bf5c2afd460ed23a28a9598332f69c7a.png](https://i-blog.csdnimg.cn/blog_migrate/1378f26a8f6edcfcef95236b3db613f2.jpeg)
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
![d0ec22106fcd9f0582efff935ccffc8a.png](https://i-blog.csdnimg.cn/blog_migrate/e55abadfd0bcd52d9fc5a9b67d30fc81.jpeg)
[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'}
![247476850624a4f68d6bcf6c7e36da24.png](https://i-blog.csdnimg.cn/blog_migrate/d47eebebce9091ce2fd02f467a15dda3.jpeg)
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
![6220120cb98956f36fe5d68a463968c5.png](https://i-blog.csdnimg.cn/blog_migrate/5ae1bfc4f3988fb48a20662969f6c385.jpeg)
[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'}
![a4bf5f24f1c83993fcd48252593c75f4.png](https://i-blog.csdnimg.cn/blog_migrate/8eaddf4e1d98f1db122b278bccfe6ff2.jpeg)