PaddleHub能夠便捷地獲取PaddlePaddle生態下的預訓練模型,完成模型的管理和一鍵預測。配合使用Fine-tune API,能夠基於大規模預訓練模型快速完成遷移學習,讓預訓練模型能更好地服務於用戶特定場景的應用。網絡
本次介紹如何使用paddlehub調用vgg模型實現圖像分類。app
模型概述ide
VGG是牛津大學計算機視覺組和DeepMind在2014年提出的一種圖像分類模型。該系列模型探索了卷積神經網絡的深度與其性能之間的關係,經過實驗證實了增長網絡的深度可以在必定程度上影響網絡最終的性能,到目前爲止,VGG仍然被許多其餘圖像任務用做特徵提取的BackBone網絡。該PaddleHub Module結構爲VGG16,基於ImageNet-2012數據集訓練,接受輸入圖片大小爲224 x 224 x 3,支持直接經過命令行或者Python接口進行預測。性能
module = hub.Module(name="vgg16_imagenet")學習
test_img_path = "./cat1.jpg"spa
# 預測結果展現命令行
img = mpimg.imread(test_img_path)orm
plt.imshow(img)blog
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)
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}]
總體效果至關不錯。