运维开发网

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

运维开发网 https://www.qedev.com 2020-01-21 15:45 出处:网络 作者:才能我浪费
PaddleHub可以便捷地获取PaddlePaddle生态下的预训练模型,完成模型的管理和一键预测。配合使用Fine-tune API,可以基于大规模预训练模型快速完成迁移学习,让预训练模型能更好地服务于用户特定场景的应用。模型概述人体解析(Human Parsing)是细粒度的语义分割任务,其旨在识别像素级别的人类图像的组成部分(例如,身体部位和服装)。ACE2P通过融合底层特征,全局上下文信

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实现人体解析

0

精彩评论

暂无评论...
验证码 换一张
取 消