PaddleHub能够便捷地获取PaddlePaddle生态下的预训练模型,完成模型的管理和一键预测。配合使用Fine-tune API,能够基于大规模预训练模型快速完成迁移学习,让预训练模型能更好地服务于用户特定场景的应用。网络
本次介绍如何使用paddlehub调用vgg模型实现图像分类。性能
模型概述学习
VGG是牛津大学计算机视觉组和DeepMind在2014年提出的一种图像分类模型。该系列模型探索了卷积神经网络的深度与其性能之间的关系,经过实验证实了增长网络的深度可以在必定程度上影响网络最终的性能,到目前为止,VGG仍然被许多其余图像任务用做特征提取的BackBone网络。该PaddleHub Module结构为VGG16,基于ImageNet-2012数据集训练,接受输入图片大小为224 x 224 x 3,支持直接经过命令行或者Python接口进行预测。命令行
module = hub.Module(name="vgg16_imagenet")blog
test_img_path = "./cat1.jpg"接口
# 预测结果展现图片
img = mpimg.imread(test_img_path)input
plt.imshow(img)io
plt.axis('off')class
plt.show()
# set input dict
input_dict = {"image": [test_img_path]}
# execute predict and print the result
results = module.classification(data=input_dict)
for result in results:
print(result)
test_img_path = "./dog1.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.classification(data=input_dict)
for result in results:
print(result)
[2020-01-03 09:19:50,058] [ INFO] - Installing vgg16_imagenet module
2020-01-03 09:19:50,058-INFO: Installing vgg16_imagenet module
Downloading vgg16_imagenet
[==================================================] 100.00%
Uncompress /home/aistudio/.paddlehub/cache/vgg16_imagenet
[==================================================] 100.00%
[2020-01-03 09:20:10,875] [ INFO] - Successfully installed vgg16_imagenet-1.0.0
2020-01-03 09:20:10,875-INFO: Successfully installed vgg16_imagenet-1.0.0
[2020-01-03 09:20:11,640] [ INFO] - 32 pretrained paramaters loaded by PaddleHub
2020-01-03 09:20:11,640-INFO: 32 pretrained paramaters loaded by PaddleHub
[{'tiger cat': 0.600113570690155}]
[{'Labrador retriever': 0.9380330443382263}]
总体效果至关不错。