百度AI攻略:Paddlehub实现人体解析

PaddleHub可以便捷地获取PaddlePaddle生态下的预训练模型,完成模型的管理和一键预测。配合使用Fine-tune API,可以基于大规模预训练模型快速完成迁移学习,让预训练模型能更好地服务于用户特定场景的应用。

模型概述

人体解析(Human Parsing)是细粒度的语义分割任务,其旨在识别像素级别的人类图像的组成部分(例如,身体部位和服装)。ACE2P通过融合底层特征,全局上下文信息和边缘细节,端到端地训练学习人体解析任务。该结构针对Intersection over Union指标进行针对性的优化学习,提升准确率。以ACE2P单人人体解析网络为基础的解决方案在CVPR2019第三届LIP挑战赛中赢得了全部三个人体解析任务的第一名。该PaddleHub Module采用ResNet101作为骨干网络,接受输入图片大小为473x473x3。

 

API

def segmentation(data)

用于人像分割

参数

data:dict类型,key为image,str类型;value为待分割的图片路径,list类型。
output_dir:生成图片的保存路径,默认为 ace2p_output

返回

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'}

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值