PaddleHub可以便捷地獲取PaddlePaddle生態(tài)下的預(yù)訓(xùn)練模型,完成模型的管理和一鍵預(yù)測。配合使用Fine-tune API,可以基于大規(guī)模預(yù)訓(xùn)練模型快速完成遷移學(xué)習(xí),讓預(yù)訓(xùn)練模型能更好地服務(wù)于用戶特定場景的應(yīng)用。
模型概述:
模型概述
Faster_RCNN是兩階段目標檢測器。通過對圖像生成候選區(qū)域,提取特征,判別特征類別并修正候選框位置。Faster_RCNN整體網(wǎng)絡(luò)可以分為4個主要內(nèi)容,一是ResNet-50作為基礎(chǔ)卷積層,二是區(qū)域生成網(wǎng)絡(luò),三是Rol Align,四是檢測層。Faster_RCNN是在MS-COCO數(shù)據(jù)集上預(yù)訓(xùn)練的模型。該PaddleHub Module可支持預(yù)測。
代碼及效果示例:
import paddlehub as hub
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
#faster_rcnn_coco2017
module = hub.Module(name="faster_rcnn_coco2017")
test_img_path = "./body2.jpg"
# 預(yù)測結(jié)果展示
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.object_detection(data=input_dict)
for result in results:
? ? print(result)
test_img_path = "./output/body2.jpg"
img = mpimg.imread(test_img_path)
plt.imshow(img)
plt.axis('off')
plt.show()
[2020-01-08 06:54:40,430] [? ? INFO] - Installing faster_rcnn_coco2017 module
2020-01-08 06:54:40,430-INFO: Installing faster_rcnn_coco2017 module
[2020-01-08 06:54:40,462] [? ? INFO] - Module faster_rcnn_coco2017 already installed in /home/aistudio/.paddlehub/modules/faster_rcnn_coco2017
2020-01-08 06:54:40,462-INFO: Module faster_rcnn_coco2017 already installed in /home/aistudio/.paddlehub/modules/faster_rcnn_coco2017
?
[2020-01-08 06:54:40,984] [? ? INFO] - 169 pretrained paramaters loaded by PaddleHub
2020-01-08 06:54:40,984-INFO: 169 pretrained paramaters loaded by PaddleHub
image with bbox drawed saved as /home/aistudio/work/output/body2.jpg
{'path': './body2.jpg', 'data': [{'left': 89.073586, 'right': 331.32816, 'top': 50.749474, 'bottom': 277.31653, 'label': 'person', 'confidence': 0.9966834}]}
?
In[6]
import paddlehub as hub
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
#faster_rcnn_coco2017
module = hub.Module(name="faster_rcnn_coco2017")
test_img_path = "./body1.jpg"
# 預(yù)測結(jié)果展示
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.object_detection(data=input_dict)
for result in results:
? ? print(result)
test_img_path = "./output/body1.jpg"
img = mpimg.imread(test_img_path)
plt.imshow(img)
plt.axis('off')
plt.show()
[2020-01-08 06:55:16,472] [? ? INFO] - Installing faster_rcnn_coco2017 module
2020-01-08 06:55:16,472-INFO: Installing faster_rcnn_coco2017 module
[2020-01-08 06:55:16,483] [? ? INFO] - Module faster_rcnn_coco2017 already installed in /home/aistudio/.paddlehub/modules/faster_rcnn_coco2017
2020-01-08 06:55:16,483-INFO: Module faster_rcnn_coco2017 already installed in /home/aistudio/.paddlehub/modules/faster_rcnn_coco2017
?

[2020-01-08 06:55:17,044] [? ? INFO] - 169 pretrained paramaters loaded by PaddleHub
2020-01-08 06:55:17,044-INFO: 169 pretrained paramaters loaded by PaddleHub
image with bbox drawed saved as /home/aistudio/work/output/body1.jpg
{'path': './body1.jpg', 'data': [{'left': 333.45242, 'right': 802.91956, 'top': 318.4439, 'bottom': 1052.2673, 'label': 'person', 'confidence': 0.7535156}, {'left': 209.79471, 'right': 795.71326, 'top': 319.2016, 'bottom': 1515.5725, 'label': 'person', 'confidence': 0.99797016}, {'left': 723.31616, 'right': 1350.0393, 'top': 217.41296, 'bottom': 1949.7135, 'label': 'person', 'confidence': 0.9976978}, {'left': 264.5524, 'right': 828.4072, 'top': 852.47485, 'bottom': 2025.8547, 'label': 'person', 'confidence': 0.84229875}, {'left': 734.1046, 'right': 1297.6768, 'top': 236.46027, 'bottom': 1131.4011, 'label': 'person', 'confidence': 0.99232954}, {'left': 736.2953, 'right': 1197.4048, 'top': 893.317, 'bottom': 2082.668, 'label': 'person', 'confidence': 0.74164623}, {'left': 1153.4473, 'right': 1451.6208, 'top': 1204.4583, 'bottom': 1735.3435, 'label': 'handbag', 'confidence': 0.6623996}]}
?

In[7]
import paddlehub as hub
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
#faster_rcnn_coco2017
module = hub.Module(name="faster_rcnn_coco2017")
test_img_path = "./vehicle1.jpg"
# 預(yù)測結(jié)果展示
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.object_detection(data=input_dict)
for result in results:
? ? print(result)
test_img_path = "./output/vehicle1.jpg"
img = mpimg.imread(test_img_path)
plt.imshow(img)
plt.axis('off')
plt.show()
[2020-01-08 06:55:41,351] [? ? INFO] - Installing faster_rcnn_coco2017 module
2020-01-08 06:55:41,351-INFO: Installing faster_rcnn_coco2017 module
[2020-01-08 06:55:41,362] [? ? INFO] - Module faster_rcnn_coco2017 already installed in /home/aistudio/.paddlehub/modules/faster_rcnn_coco2017
2020-01-08 06:55:41,362-INFO: Module faster_rcnn_coco2017 already installed in /home/aistudio/.paddlehub/modules/faster_rcnn_coco2017
?
[2020-01-08 06:55:41,753] [? ? INFO] - 169 pretrained paramaters loaded by PaddleHub
2020-01-08 06:55:41,753-INFO: 169 pretrained paramaters loaded by PaddleHub
image with bbox drawed saved as /home/aistudio/work/output/vehicle1.jpg
{'path': './vehicle1.jpg', 'data': [{'left': 172.94551, 'right': 587.33716, 'top': 164.10345, 'bottom': 380.49017, 'label': 'car', 'confidence': 0.99788874}]}
?