百度AI攻略:Paddlehub实现图像分割

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

模型概述:

模型概述 DeepLabv3+ 是Google DeepLab语义分割系列网络的最新作,其前作有 DeepLabv1,DeepLabv2, DeepLabv3。在最新作中,作者通过encoder-decoder进行多尺度信息的融合,同时保留了原来的空洞卷积和ASSP层, 其骨干网络使用了Xception模型,提高了语义分割的健壮性和运行速率,在 PASCAL VOC 2012 dataset取得新的state-of-art performance。该PaddleHub Module使用百度自建数据集进行训练,可用于人像分割,支持任意大小的图片输入。

代码及效果示例:

import paddlehub as hub
import matplotlib.pyplot as plt 
import matplotlib.image as mpimg 
#deeplabv3p_xception65_humanseg
module = hub.Module(name="deeplabv3p_xception65_humanseg")
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 = "./humanseg_output/body2.png"
img = mpimg.imread(test_img_path)
plt.imshow(img) 
plt.axis('off') 
plt.show()
[2020-01-07 06:03:45,652] [    INFO] - Installing deeplabv3p_xception65_humanseg module
2020-01-07 06:03:45,652-INFO: Installing deeplabv3p_xception65_humanseg module
[2020-01-07 06:03:45,692] [    INFO] - Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg
2020-01-07 06:03:45,692-INFO: Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg

[2020-01-07 06:03:46,479] [    INFO] - 0 pretrained paramaters loaded by PaddleHub
2020-01-07 06:03:46,479-INFO: 0 pretrained paramaters loaded by PaddleHub
{'origin': './body2.jpg', 'processed': 'humanseg_output/body2.png'}

In[5]

#deeplabv3p_xception65_humanseg
module = hub.Module(name="deeplabv3p_xception65_humanseg")
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 = "./humanseg_output/body1.png"
img = mpimg.imread(test_img_path)
plt.imshow(img) 
plt.axis('off') 
plt.show()
[2020-01-07 06:04:10,459] [    INFO] - Installing deeplabv3p_xception65_humanseg module
2020-01-07 06:04:10,459-INFO: Installing deeplabv3p_xception65_humanseg module
[2020-01-07 06:04:10,476] [    INFO] - Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg
2020-01-07 06:04:10,476-INFO: Module deeplabv3p_xception65_humanseg already installed in /home/aistudio/.paddlehub/modules/deeplabv3p_xception65_humanseg

[2020-01-07 06:04:11,422] [    INFO] - 0 pretrained paramaters loaded by PaddleHub
2020-01-07 06:04:11,422-INFO: 0 pretrained paramaters loaded by PaddleHub
{'origin': './body1.jpg', 'processed': 'humanseg_output/body1.png'}

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值