[Frontier Application of Deep Learning] Target Detection
About the author : a college student, an expert on Huawei Cloud Sharing, a star blogger of Alibaba Cloud, a member of Tengyun Pioneer (TDP), the general director of the Yunxi Smart Project, and the National Committee of Experts on Computer Teaching and Industrial Practice Resource Construction in Colleges and Universities ( TIPCC ) Volunteers , as well as programming enthusiasts, look forward to learning and making progress together with everyone~
.
Blog homepage :ぃ Ling Yu が's learning log
.
This article column : artificial intelligence
. The sea is unstoppable .
Article directory
foreword
1. How does the computer achieve object detection?
For a computer, what it can "see" is the number after the image is encoded, but it is difficult to understand high-level semantic concepts, such as whether the target appearing in the image or video frame is a person or an object, and it is impossible to locate the target appearing in the image. that area.
2. What is the main purpose of object detection?
The main purpose of object detection is to allow the computer to automatically identify the category of all objects in a picture or video frame, and draw a bounding box around the object to mark the location of each object.
3. What is the process of object detection?
The process of target detection is: generate a series of areas that may contain objects on the input image, these areas are called candidate areas (many candidate areas can be generated on one image), and then for each candidate area, you can Treat it as an image by itself and use an image classification model to classify it to see which class or background it belongs to (i.e. a class that does not contain any objects).
本实验的目的是简单地演示如何使用PaddleHub工具,实现目标检测(推理过程,如何使用飞桨深度学习平台进行预训练,而微调的实验将在后面的小节介绍),本次实验平台为百度AI Studio,实验环境为Python 3.7,Paddle2.0,PaddleHub2.0
(1), load the picture to be detected
Import related packages
import paddlehub as hub
import cv2
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
Using different pretrained models, detect the objects shown in Figure 1 below:
注:使用时可能会出现版本不对应的情况,需在导入包之前,加入如下代码:
!pip uninstall paddlepaddle
!pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple
!pip uninstall paddlehub
!pip install paddlehub -i https://pypi.tuna.tsinghua.edu.cn/simple
(2), define the target detection function
Since PaddleHub provides a variety of target detection pre-training models, you can try to use different pre-training models for detection, and control the calling model type through parameters:
# 定义目标检测接口函数:module_name为选择的预训练模型名称
def object_detection(module_name):
vehicles_detector = hub.Module(name=module_name)
result = vehicles_detector.object_detection(images=[cv2.imread('motuoche2.jpg')])
img = mpimg.imread(result[0]['save_path'])
plt.figure(figsize=(15,15))
plt.imshow(img)
plt.show()
(3), target detection
Since Figure 1 contains vehicles and people, this experiment uses the following four pre-trained models for detection, and displays the detection results: yolov3_darknet53_pedestrian, yolov3_darknet53_vehicles, yolov3_darknet53_v1_coco2017, and faster_rcnn_resnet50_fpn_coco2017
object_detection('yolov3_darknet53_pedestrian') # 行人检测
The detection results are shown in Figure 2 below:
#Can detect pedestrians
object_detection('yolov3_darknet53_vehicles') # 车辆
The detection results are shown in Figure 3 below:
#Detectable vehicles
object_detection('yolov3_mobilenet_v1_coco2017') # 车辆及行人
The detection results are shown in Figure 4 below:
#Can detect vehicles and pedestrians
object_detection('faster_rcnn_resnet50_fpn_coco2017') # 车辆及行人
The detection results are shown in Figure 5 below:
# Can detect vehicles and pedestrians
Summarize
The content of this series of articles is based on the relevant notes and insights of the "Machine Learning Practice" published by Tsinghua. The code is developed based on Baidu Fei Pao. If there is any infringement or inappropriateness, please send a private message to me, and I will actively cooperate. Deal with it, you will come back when you see it! ! !
Finally, I quote a sentence from this event as the conclusion of the article~( ̄▽ ̄~)~:
[ The biggest reason for learning is to get rid of mediocrity, one day sooner, one more wonderful life; one day later, one more day of mediocrity. 】
ps: For more exciting content, please enter the column of this article : artificial intelligence , check it out, welcome everyone to support and advise~( ̄▽ ̄~)~