百度AI攻略:Paddlehub實現目標檢測

u_d5610d79507e發表於2020-01-18

PaddleHub可以便捷地獲取PaddlePaddle生態下的預訓練模型,完成模型的管理和一鍵預測。配合使用Fine-tune API,可以基於大規模預訓練模型快速完成遷移學習,讓預訓練模型能更好地服務於使用者特定場景的應用。

模型概述:

模型概述

Faster_RCNN是兩階段目標檢測器。透過對影像生成候選區域,提取特徵,判別特徵類別並修正候選框位置。Faster_RCNN整體網路可以分為4個主要內容,一是ResNet-50作為基礎卷積層,二是區域生成網路,三是Rol Align,四是檢測層。Faster_RCNN是在MS-COCO資料集上預訓練的模型。該PaddleHub Module可支援預測。

程式碼及效果示例:

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"

# 預測結果展示

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

百度AI攻略:Paddlehub實現目標檢測

[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}]}

百度AI攻略:Paddlehub實現目標檢測

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"

# 預測結果展示

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

百度AI攻略:Paddlehub實現目標檢測

[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}]}

百度AI攻略:Paddlehub實現目標檢測

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"

# 預測結果展示

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

百度AI攻略:Paddlehub實現目標檢測

[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}]}

百度AI攻略:Paddlehub實現目標檢測


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69922494/viewspace-2673936/,如需轉載,請註明出處,否則將追究法律責任。

相關文章