TensorFlow中的对象检测教程:实时对象检测

导言


创建能够在单个图像中识别和定位多个对象的精确机器学习模型仍然是计算机视觉中的核心挑战。但随着最近深度学习的进步,对象检测应用程序比以往更容易开发。TensorFlow的对象检测API是一个构建与TensorFlow之上的开源框架,可以轻松的构建、训练和部署对象检测模型。

什么是物体检测?


对象检测是在静止图像或视频中查找真实世界对象实例(如汽车、自行车、电视、鲜花和人类)的过程。它允许识别、定位和检测图像中的多个对象,这使得我们能够更好的理解整个图像。它通常用于图像检索、安全、监视和高级驾驶员辅助系统(ADAS)等应用。


对象检测可疑通过一下多种方式完成:

  • 基于特征的对象检测

  • Viola Jones物体检测

  • 具有HOG功能的SVM分类

  • 深度学习对象检测


在这个对象检测教程中,我们将专注于深度学习对象检测,因为TensorFlow使用深度学习进行计算。

640?wx_fmt=png

物体检测的应用

面部识别

640?wx_fmt=jpeg

Facebook的一组研究人员开发了一种名为“DeepFace”的深度学习面部识别系统,可以非常有限的识别数字图像中的人脸。Google在Google相册中使用自己的面部识别系统,该系统会根据图片中的人物自动隔离所有照片。面部识别涉及各种组件,例如眼睛、鼻子、嘴巴和眉毛。


人数统计

640?wx_fmt=png


对象检测也可用于人数统计。它用于在节日期间分析商场、景区的人流量。这是一项非常重要的应用程序,因为在人群聚会期间,此功能可用于多种用途。


工业质量检查

640?wx_fmt=png


物体检测还用于工业过程中以识别产品。通过目视检查寻找特定对象是一项基本任务,涉及多个工业流程,如分拣、质量管理、包装等。

库存管理可能非常棘手,因为物品难以实时跟踪。自动对象计数和本地化可以提高库存准确性。


自驾车

640?wx_fmt=png


自动驾驶汽车是未来的趋势,他结合了各种技术来感知周围环境,包括雷达、激光、GPS、测距和计算机视觉。


先进的控制系统解释感官信息以识别适当的导航路径以及障碍物,并且一旦图像传感器检测到其路径中的任何生物迹象,它就会自动停止,这种情况发生的非常快,使得无人驾驶向前迈进了一大步。


安全

640?wx_fmt=gif

对象检测在安全性中起着非常重要的作用。无论是Apple的面部IS还是所有科幻电影中使用的视网膜扫描。


政府还使用它与现有的数据库进行匹配,以查找任何罪犯或检测劫匪的车辆。

对象检测工作流程


每个对象检测算法都有不同的工作方式,但它们都以相同的原理工作。


特征提取:它们从输入图像中提取特征,并使用这些特征来确定图像的类别。通过MatLab,OpenCV,Viola Jones或深度学习。

640?wx_fmt=png

什么是TensorFlow?


TensorFlow是Google的开源机器学习框架,用于跨越一系列任务进行数据流编程。图中的节点表示数学运算,而图表边表示在它们之间通信的多维数据阵列。

640?wx_fmt=png

对象检测教程


先决条件

在演示之前,先看一下提前要准备的:

  • Python

  • TensorFlow

  • TensorBoard

  • Protobuf v3.4 或以上版本


建立环境

要下载TensorFlow和TensorFlow GPU,可以使用pip或conda命令:

 
 
1# For CPU2pip install tensorflow3# For GPU4pip install tensorflow-gpu# For CPU
2pip install tensorflow
3# For GPU
4pip install tensorflow-gpu


对于其他库,同样可以使用pip或conda来安装,代码如下:

 
 
1pip install --user Cython2pip install --user contextlib23pip install --user pillow4pip install --user lxml5pip install --user jupyter6pip install --user matplotlib
2pip install --user contextlib2
3pip install --user pillow
4pip install --user lxml
5pip install --user jupyter
6pip install --user matplotlib


接下来,我们有Protobuf:Protocol Buffers是Google的可扩展的用于序列化结构化数据。可将其视为XML,但更小、更快、更简单。


为了简单起见,我们将一个名为“Tensorflow”的文件夹下保留“models”和“protobuf”。接下来需要进入Tensorflow文件夹,并使用命令运行protobuf:

 
 
1"path_of_protobuf's bin"./bin/protoc object_detection/protos/"path_of_protobuf's bin"./bin/protoc object_detection/protos/


要检查是否有效,可以转到models> object_detection> protos中的protos文件夹,在那里可以看到每个proto文件都创建了一个python文件。


主要代码

640?wx_fmt=jpeg


设置环境后,需要转到“”目录并创建一个新的python文件。可以使用Spyder或Jupyter编写代码。


首先,导入所有库。

 
 
 1import numpy as np 2import os 3import six.moves.urllib as urllib 4import sys 5import tarfile 6import tensorflow as tf 7import zipfile 8from collections import defaultdict 9from io import StringIO10from matplotlib import pyplot as plt11from PIL import Image12sys.path.append("..")13from object_detection.utils import ops as utils_ops14from utils import label_map_util15from utils import visualization_utils as vis_utilimport numpy as np
2import os
3import six.moves.urllib as urllib
4import sys
5import tarfile
6import tensorflow as tf
7import zipfile
8from collections import defaultdict
9from io import StringIO
10from matplotlib import pyplot as plt
11from PIL import Image
12sys.path.append("..")
13from object_detection.utils import ops as utils_ops
14from utils import label_map_util
15from utils import visualization_utils as vis_util


接下来,将下载在COCO数据集上训练的模型。COCO代表上下文中的公共对象,该数据集包含大约330K标记图像。模型选择非常重要,因为需要在速度和准确度之间进行权衡。根据你的需求和系统内存,必须选择正确的型号。


models> research> object_detection> g3doc> detection_model_zoo”包含具有不同速度和准确度的所有模型。

640?wx_fmt=png



接下来,我们提供Tensorflow生成的所需模型和frozen inference graph。

 
 
1MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'2MODEL_FILE = MODEL_NAME + '.tar.gz'3DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'4PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'5PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt')6NUM_CLASSES = 90'ssd_mobilenet_v1_coco_2017_11_17'
2MODEL_FILE = MODEL_NAME + '.tar.gz'
3DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'
4PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'
5PATH_TO_LABELS = os.path.join('data''mscoco_label_map.pbtxt')
6NUM_CLASSES = 90


此代码将从网上下载该模型并提取该模型的frozen inference graph。

 
 
 1opener = urllib.request.URLopener() 2opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE) 3tar_file = tarfile.open(MODEL_FILE) 4for file in tar_file.getmembers(): 5  file_name = os.path.basename(file.name) 6  if 'frozen_inference_graph.pb' in file_name: 7    tar_file.extract(file, os.getcwd()) 8detection_graph = tf.Graph() 9with detection_graph.as_default():10  od_graph_def = tf.GraphDef()11  with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:12    serialized_graph = fid.read()13    od_graph_def.ParseFromString(serialized_graph)14    tf.import_graph_def(od_graph_def, name='')
2opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
3tar_file = tarfile.open(MODEL_FILE)
4for file in tar_file.getmembers():
5  file_name = os.path.basename(file.name)
6  if 'frozen_inference_graph.pb' in file_name:
7    tar_file.extract(file, os.getcwd())
8detection_graph = tf.Graph()
9with detection_graph.as_default():
10  od_graph_def = tf.GraphDef()
11  with tf.gfile.GFile(PATH_TO_CKPT, 'rb'as fid:
12    serialized_graph = fid.read()
13    od_graph_def.ParseFromString(serialized_graph)
14    tf.import_graph_def(od_graph_def, name='')


接下来,将加载所有标签

 
 
1label_map = label_map_util.load_labelmap(PATH_TO_LABELS)2categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)3category_index = label_map_util.create_category_index(categories)
2categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
3category_index = label_map_util.create_category_index(categories)


现在将图像的数据转换为numPy数组进行处理

 
 
1def load_image_into_numpy_array(image):2  (im_width, im_height) = image.size3  return np.array(image.getdata()).reshape(4      (im_height, im_width, 3)).astype(np.uint8)def load_image_into_numpy_array(image):
2  (im_width, im_height) = image.size
3  return np.array(image.getdata()).reshape(
4      (im_height, im_width, 3)).astype(np.uint8)


此处定义了用于测试目的的图像路径,对于i(1到n+1),有一个命名约定“image[i]”,n是提供的图像数量。

 
 
1PATH_TO_TEST_IMAGES_DIR = 'test_images'2TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, 'image{}.jpg'.format(i)) for i in range(1, 8) ]'test_images'
2TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, 'image{}.jpg'.format(i)) for i in range(18) ]


此代码运行单个图像的推断,其中它检测对象、画框,并提供该特定对象的类和类的得分。

 
 
 1def run_inference_for_single_image(image, graph): 2  with graph.as_default(): 3    with tf.Session() as sess: 4    # Get handles to input and output tensors 5      ops = tf.get_default_graph().get_operations() 6      all_tensor_names = {output.name for op in ops for output in op.outputs} 7      tensor_dict = {} 8      for key in [ 9          'num_detections', 'detection_boxes', 'detection_scores',10          'detection_classes', 'detection_masks'11     ]:12        tensor_name = key + ':0'13        if tensor_name in all_tensor_names:14          tensor_dict[key] = tf.get_default_graph().get_tensor_by_name(15            tensor_name)16      if 'detection_masks' in tensor_dict:17        # The following processing is only for single image18        detection_boxes = tf.squeeze(tensor_dict['detection_boxes'], [0])19        detection_masks = tf.squeeze(tensor_dict['detection_masks'], [0])20        # Reframe is required to translate mask from box coordinates to image coordinates and fit the image size.21        real_num_detection = tf.cast(tensor_dict['num_detections'][0], tf.int32)22        detection_boxes = tf.slice(detection_boxes, [0, 0], [real_num_detection, -1])23        detection_masks = tf.slice(detection_masks, [0, 0, 0], [real_num_detection, -1, -1])24        detection_masks_reframed = utils_ops.reframe_box_masks_to_image_masks(25            detection_masks, detection_boxes, image.shape[0], image.shape[1])26        detection_masks_reframed = tf.cast(27            tf.greater(detection_masks_reframed, 0.5), tf.uint8)28        # Follow the convention by adding back the batch dimension29        tensor_dict['detection_masks'] = tf.expand_dims(30            detection_masks_reframed, 0)31        image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')32        # Run inference33        output_dict = sess.run(tensor_dict,34            feed_dict={image_tensor: np.expand_dims(image, 0)})35        # all outputs are float32 numpy arrays, so convert types as appropriate36        output_dict['num_detections'] = int(output_dict['num_detections'][0])37        output_dict['detection_classes'] = output_dict[38          'detection_classes'][0].astype(np.uint8)39        output_dict['detection_boxes'] = output_dict['detection_boxes'][0]40        output_dict['detection_scores'] = output_dict['detection_scores'][0]41        if 'detection_masks' in output_dict:42          output_dict['detection_masks'] = output_dict['detection_masks'][0]43return output_dictdef run_inference_for_single_image(image, graph):
2  with graph.as_default():
3    with tf.Session() as sess:
4    # Get handles to input and output tensors
5      ops = tf.get_default_graph().get_operations()
6      all_tensor_names = {output.name for op in ops for output in op.outputs}
7      tensor_dict = {}
8      for key in [
9          'num_detections''detection_boxes''detection_scores',
10          'detection_classes''detection_masks'
11     ]:
12        tensor_name = key + ':0'
13        if tensor_name in all_tensor_names:
14          tensor_dict[key] = tf.get_default_graph().get_tensor_by_name(
15            tensor_name)
16      if 'detection_masks' in tensor_dict:
17        # The following processing is only for single image
18        detection_boxes = tf.squeeze(tensor_dict['detection_boxes'], [0])
19        detection_masks = tf.squeeze(tensor_dict['detection_masks'], [0])
20        # Reframe is required to translate mask from box coordinates to image coordinates and fit the image size.
21        real_num_detection = tf.cast(tensor_dict['num_detections'][0], tf.int32)
22        detection_boxes = tf.slice(detection_boxes, [00], [real_num_detection, -1])
23        detection_masks = tf.slice(detection_masks, [000], [real_num_detection, -1-1])
24        detection_masks_reframed = utils_ops.reframe_box_masks_to_image_masks(
25            detection_masks, detection_boxes, image.shape[0], image.shape[1])
26        detection_masks_reframed = tf.cast(
27            tf.greater(detection_masks_reframed, 0.5), tf.uint8)
28        # Follow the convention by adding back the batch dimension
29        tensor_dict['detection_masks'] = tf.expand_dims(
30            detection_masks_reframed, 0)
31        image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')
32        # Run inference
33        output_dict = sess.run(tensor_dict,
34            feed_dict={image_tensor: np.expand_dims(image, 0)})
35        # all outputs are float32 numpy arrays, so convert types as appropriate
36        output_dict['num_detections'] = int(output_dict['num_detections'][0])
37        output_dict['detection_classes'] = output_dict[
38          'detection_classes'][0].astype(np.uint8)
39        output_dict['detection_boxes'] = output_dict['detection_boxes'][0]
40        output_dict['detection_scores'] = output_dict['detection_scores'][0]
41        if 'detection_masks' in output_dict:
42          output_dict['detection_masks'] = output_dict['detection_masks'][0]
43return output_dict


我们的最终循环将调用上面定义所有函数,将逐个对所有输入图像进行推理,这将为我们提供图像的输出,其中使用标签检测对象,并且该对象的百分比/分数类似于训练数据。

 
 
 1for image_path in TEST_IMAGE_PATHS: 2  image = Image.open(image_path) 3  # the array based representation of the image will be used later in order to prepare the 4  # result image with boxes and labels on it. 5  image_np = load_image_into_numpy_array(image) 6  # Expand dimensions since the model expects images to have shape: [1, None, None, 3] 7  image_np_expanded = np.expand_dims(image_np, axis=0) 8  # Actual detection. 9  output_dict = run_inference_for_single_image(image_np, detection_graph)10  # Visualization of the results of a detection.11  vis_util.visualize_boxes_and_labels_on_image_array(12      image_np,13      output_dict['detection_boxes'],14      output_dict['detection_classes'],15      output_dict['detection_scores'],16      category_index,17      instance_masks=output_dict.get('detection_masks'),18      use_normalized_coordinates=True,19      line_thickness=8)20plt.figure(figsize=IMAGE_SIZE)21plt.imshow(image_np)for image_path in TEST_IMAGE_PATHS:
2  image = Image.open(image_path)
3  # the array based representation of the image will be used later in order to prepare the
4  # result image with boxes and labels on it.
5  image_np = load_image_into_numpy_array(image)
6  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
7  image_np_expanded = np.expand_dims(image_np, axis=0)
8  # Actual detection.
9  output_dict = run_inference_for_single_image(image_np, detection_graph)
10  # Visualization of the results of a detection.
11  vis_util.visualize_boxes_and_labels_on_image_array(
12      image_np,
13      output_dict['detection_boxes'],
14      output_dict['detection_classes'],
15      output_dict['detection_scores'],
16      category_index,
17      instance_masks=output_dict.get('detection_masks'),
18      use_normalized_coordinates=True,
19      line_thickness=8)
20plt.figure(figsize=IMAGE_SIZE)
21plt.imshow(image_np)

640?wx_fmt=png

640?wx_fmt=png


现在,让我们看看如何检测实时视频中的对象。

使用Tensorflow进行实时物体检测


对于本演示,我们将使用相同的代码,但会调整一些内容,将使用OpenCV和相机模块使用网络摄像头的实时反馈来检测对象。


添加OpenCV库和用于铺货图像的相机,只需将以下行添加到导入库部分即可。

 
 
1import cv22cap = cv2.VideoCapture(0)import cv2
2cap = cv2.VideoCapture(0)


我们不需要从目录加载图像并将其转换为numPy数组,因为OpenCV将为我们处理。

替换这里:

 
 
1for image_path in TEST_IMAGE_PATHS:2image = Image.open(image_path)3# the array based representation of the image will be used later in order to prepare the4# result image with boxes and labels on it.5image_np = load_image_into_numpy_array(image)for image_path in TEST_IMAGE_PATHS:
2image = Image.open(image_path)
3# the array based representation of the image will be used later in order to prepare the
4# result image with boxes and labels on it.
5image_np = load_image_into_numpy_array(image)


得到这个:

 
 
1while True:2ret, image_np = cap.read()while True:
2ret, image_np = cap.read()


我们不会使用matplotlib进行最终图像显示,我们使用OpenCV。

删除这里:

 
 
1cv2.imshow('object detection', cv2.resize(image_np, (800,600)))2if cv2.waitKey(25) & 0xFF == ord('q'):3  cv2.destroyAllWindows()4  break'object detection', cv2.resize(image_np, (800,600)))
2if cv2.waitKey(25) & 0xFF == ord('q'):
3  cv2.destroyAllWindows()
4  break


OpenCV将使用先前初始化的相机对象打开名为“Object_Detection”的大小为“800*600”的新窗口。相机将等待25ms显示图像,否则将关闭窗口。


所有变更的最终代码:

 
 
 1import numpy as np 2import os 3import six.moves.urllib as urllib 4import sys 5import tarfile 6import tensorflow as tf 7import zipfile 8from collections import defaultdict 9from io import StringIO10from matplotlib import pyplot as plt11from PIL import Image12import cv213cap = cv2.VideoCapture(0)14sys.path.append("..")15from utils import label_map_util16from utils import visualization_utils as vis_util17MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'18MODEL_FILE = MODEL_NAME + '.tar.gz'19DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'20# Path to frozen detection graph. This is the actual model that is used for the object detection.21PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'22# List of the strings that is used to add correct label for each box.23PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt')24NUM_CLASSES = 9025opener = urllib.request.URLopener()26opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)27tar_file = tarfile.open(MODEL_FILE)28for file in tar_file.getmembers():29  file_name = os.path.basename(file.name)30  if 'frozen_inference_graph.pb' in file_name:31    tar_file.extract(file, os.getcwd())32detection_graph = tf.Graph()33with detection_graph.as_default():34  od_graph_def = tf.GraphDef()35  with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:36    serialized_graph = fid.read()37    od_graph_def.ParseFromString(serialized_graph)38    tf.import_graph_def(od_graph_def, name='')39label_map = label_map_util.load_labelmap(PATH_TO_LABELS)40categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)41category_index = label_map_util.create_category_index(categories)42with detection_graph.as_default():43  with tf.Session(graph=detection_graph) as sess:44    while True:45    ret, image_np = cap.read()46    # Expand dimensions since the model expects images to have shape: [1, None, None, 3]47    image_np_expanded = np.expand_dims(image_np, axis=0)48    image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')49    # Each box represents a part of the image where a particular object was detected.50    boxes = detection_graph.get_tensor_by_name('detection_boxes:0')51    # Each score represent how level of confidence for each of the objects.52    # Score is shown on the result image, together with the class label.53    scores = detection_graph.get_tensor_by_name('detection_scores:0')54    classes = detection_graph.get_tensor_by_name('detection_classes:0')55    num_detections = detection_graph.get_tensor_by_name('num_detections:0')56    # Actual detection.57    (boxes, scores, classes, num_detections) = sess.run(58      [boxes, scores, classes, num_detections],59      feed_dict={image_tensor: image_np_expanded})60    # Visualization of the results of a detection.61    vis_util.visualize_boxes_and_labels_on_image_array(62        image_np,63        np.squeeze(boxes),64        np.squeeze(classes).astype(np.int32),65        np.squeeze(scores),66        category_index,67        use_normalized_coordinates=True,68        line_thickness=8)69    cv2.imshow('object detection', cv2.resize(image_np, (800,600)))70    if cv2.waitKey(25) 0xFF == ord('q'):71      cv2.destroyAllWindows()72      breakimport numpy as np
2import os
3import six.moves.urllib as urllib
4import sys
5import tarfile
6import tensorflow as tf
7import zipfile
8from collections import defaultdict
9from io import StringIO
10from matplotlib import pyplot as plt
11from PIL import Image
12import cv2
13cap = cv2.VideoCapture(0)
14sys.path.append("..")
15from utils import label_map_util
16from utils import visualization_utils as vis_util
17MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'
18MODEL_FILE = MODEL_NAME + '.tar.gz'
19DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'
20# Path to frozen detection graph. This is the actual model that is used for the object detection.
21PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'
22# List of the strings that is used to add correct label for each box.
23PATH_TO_LABELS = os.path.join('data''mscoco_label_map.pbtxt')
24NUM_CLASSES = 90
25opener = urllib.request.URLopener()
26opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
27tar_file = tarfile.open(MODEL_FILE)
28for file in tar_file.getmembers():
29  file_name = os.path.basename(file.name)
30  if 'frozen_inference_graph.pb' in file_name:
31    tar_file.extract(file, os.getcwd())
32detection_graph = tf.Graph()
33with detection_graph.as_default():
34  od_graph_def = tf.GraphDef()
35  with tf.gfile.GFile(PATH_TO_CKPT, 'rb'as fid:
36    serialized_graph = fid.read()
37    od_graph_def.ParseFromString(serialized_graph)
38    tf.import_graph_def(od_graph_def, name='')
39label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
40categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
41category_index = label_map_util.create_category_index(categories)
42with detection_graph.as_default():
43  with tf.Session(graph=detection_graph) as sess:
44    while True:
45    ret, image_np = cap.read()
46    # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
47    image_np_expanded = np.expand_dims(image_np, axis=0)
48    image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
49    # Each box represents a part of the image where a particular object was detected.
50    boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
51    # Each score represent how level of confidence for each of the objects.
52    # Score is shown on the result image, together with the class label.
53    scores = detection_graph.get_tensor_by_name('detection_scores:0')
54    classes = detection_graph.get_tensor_by_name('detection_classes:0')
55    num_detections = detection_graph.get_tensor_by_name('num_detections:0')
56    # Actual detection.
57    (boxes, scores, classes, num_detections) = sess.run(
58      [boxes, scores, classes, num_detections],
59      feed_dict={image_tensor: image_np_expanded})
60    # Visualization of the results of a detection.
61    vis_util.visualize_boxes_and_labels_on_image_array(
62        image_np,
63        np.squeeze(boxes),
64        np.squeeze(classes).astype(np.int32),
65        np.squeeze(scores),
66        category_index,
67        use_normalized_coordinates=True,
68        line_thickness=8)
69    cv2.imshow('object detection', cv2.resize(image_np, (800,600)))
70    if cv2.waitKey(250xFF == ord('q'):
71      cv2.destroyAllWindows()
72      break

结语


希望大家能够喜欢这篇文章,现在了解Tensorflow的强大功能,以及检测图像和实时视频中的对象是多么容易。熟练掌握一门技术的关键,就是多动手实践。


长按订阅更多精彩▼

640?wx_fmt=jpeg

架构师小秘圈
关注 关注
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
利用Tensorflowjs实现浏览内的快速对象检测
08-12
⚡️利用Tensorflow.js实现浏览内的快速对象检测
tensorflow对象检测模型训练
可爱一只小小鸟
06-04 1070
这个是去年5月左右做的行人检测,因为毕设有一部分需要用到这部分的模型,因此重新整理下。间遇到了很多的坑,有些问题都忘记了,只标注记得的和训练的过程,这个是跟着贾志刚老师的课程学习的。在课程没有将如何标注自己想要的对象,博文与课程的区别是用LabelImage工具生成自己想要的对象,我自己训练的是标注“head”,有需要的话可以私聊我,找我拿训练好的“head”对象模型,由于电脑环境改过,文章...
Python深度学习基于Tensorflow(10)目标检测
最新发布
bigcrab的博客
05-15 395
选择性搜索(Selective Search, SS)方法是通过图像的纹理,边缘,颜色等信息对图像进行自底向上的分割,然后对分割区域进行不同尺度的合并,在合并过程,每生成一个新的区域就产生一个候选框,区域肯定是不规则,我们通过选取区域的最大外接矩阵作为候选框区域,这种方法速度较慢;普通池化固定的是操作,处理后的尺寸是动态的;由于神经网络操作需要输入的尺寸一样才能进行一些常规的算法操作,而框定的图像由于边框回归,锚框比例和大小的作用下,出现图像大小不一致的情况,这里我们需要把图像大小固定为某一尺寸;
基于Tensorflow的自定义对象识别检测模型的训练及视频实时识别(二)
yang1159的博客
04-25 2458
#开题 一、 Python 、Tensorflow 安装及环境配置 二、 Object Detection API配置 三、 LabelImage对训练样本标注处理 四、 标注后训练样本验证样本格式转换tfrecord 五、 训练模型选取及参数配置 六、 定位在Object Detection文件下train.py开始训练 七、 上一步训练结果固化成pb模型 八、 视频流调用模型预测 基于Te...
【OpenCV进阶】从深度学习环境搭建到Tensorflow行人识别,超详细!
欢迎时常光顾我的干货超市,热衷于AIoT!!
07-30 1436
一、安装 安装tensorflow pip install tensorflow 安装python pip install opencv-python 安装IDE-Pycharm
使用 TensorFlow.js 在浏览器进行自定义对象检测
Meta.Qing的博客
09-15 1460
对象检测检测对象在图像的位置并对给定图像的每个感兴趣对象进行分类的任务。在计算机视觉,该技术用于图片检索、安全摄像头和自动驾驶汽车等应用。用于对象检测的最著名的深度卷积神经网络 (DNN) 系列之一是 YOLO(You Only Look Once)。在这篇文章,我们将使用TensorFlow开发一个端到端的解决方案,在Python训练一个自定义对象检测模型,然后将其投入生产,并通过在浏览器运行实时推理。这篇文章将分为四个步骤,如下:训练一个好的模型的第一步是拥有高质量的数据。
TensorFlow物体识别——通过机器学习搭建属于自己的物体识别
热门推荐
迷途无归的博客
06-03 2万+
       由于每个项目需要检查的目标对象都不一定相同,一个大而全面的库固然是好多,但是如果仅仅是为了识别一个视角的一种或少数种类的物体,庞大的库就会显得笨重,严重占用cpu资源和存储空间。       所以这就需要我们通过机器机器学习完成特殊物体的库。本次我的检测目标物体是茶杯,所以我在网上收集了大量的图标并进行了标记,然后通过机器训练生产了自己的库,最后完成物体有有效识别。        ...
使用TensorFlow.js进行对象检测入门
weixin_26750481的博客
09-14 900
In deep learning, one of the most widely-used technologies is TensorFlow, an end-to-end open-source platform for building models. It has a vast, flexible ecosystem of tools, libraries, and community r...
使用 TensorFlow.js 在浏览器自定义目标检测
tensorflowforum的博客
07-28 1950
目标检测是一类检测目标在图像的位置,以及在给定图像对每个感兴趣的目标进行分类的任务。在计算机视觉领域,我们可将此技术应用于图片检索、监控摄像头和无人驾驶汽车 就目标检测而言,深度卷积神经网络 (DNN) 家族最负盛名的算法就是 YOLO (You Only Look Once)。 在本文,我们将使用 TensorFlow 开发一种端到端解决方案, 用以在 Python 训练自定义目标检测模型,然后将其投入生产,并通过TensorFlow.js在浏览器内运行实时推理。 项目代码库 ..
目标检测 tensorflow(预训练模型)
weixin_30902251的博客
05-27 307
tensorflow detection model zoo: 在这个链接当哦有训练好的checkpoint: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md 这里的模型是基于COCO dataset, Kitti dataset, Oe...
TensorFlow Object Detection API入门例子 (小浣熊检测下)
Dlog的博客
03-25 593
上篇文章讲了两点: 收集并标注数据 数据格式转换(tfRecord) 接下来我们来讲 确定训练模型 开始训练 导出模型并测试 好,那我们就开始吧~~~ 一 训练模型 模型选择 创建一个data文件夹把train.record和test.record放进去 Tensorflow detection model zoo 提供了很多模型 链接:https://github.com/tensor...
tensorflow_tutorial_complement:Jupyter Notebooks作为TensorFlow对象检测教程的补充
04-13
TensorFlow对象检测教程的自学需要比我原先认为需要的更多故障排除方法。 我正在共享这些文件,以通过解决方法帮助其他人使本教程正常工作。 要使用此存储库,请参阅上的教程。 一般注意事项: 我建议您为...
TensorFlowObjectDetectionTutorial:使用TensorFlow进行对象检测教程
05-09
TensorFlow对象检测API教程 最初,本教程是在考虑TensorFlow 1的情况下编写的。 由于可能仍有许多用户对使用TensorFlow 1感兴趣,因此在可预见的将来还将保留本教程的版本。 要阅读该教程,请访问 。
tensorflow-object-detection:Azure在Azure上操作TensorFlow对象检测
01-29
在Azure上操作TensorFlow对象检测第1部分:使用Docker和深度学习VM 第2部分:使用Kubernetes运行分布式TensorFlow对象检测API 第3部分:使用TensorFlow服务进行服务
gesture-tensorflow:使用Tensorflow对象检测和Python进行实时手势检测
03-08
手势张量流使用Tensorflow对象检测和Python进行实时手语检测 :snake: 安装该项目需要 , 和Tensorflow对象检测软件包才能正常运行。 您可以使用pip直接安装前两个(如果愿意,也可以使用conda ): $ pip install ...
tensorflow-face-detection:基于mobilenet SSD的面部检测器,由tensorflow对象检测api驱动,由WIDERFACE数据集训练
02-06
Tensorflow人脸检测器 提供基于Mobilenet SSD(单发多盒检测器)的人脸检测器并提供预训练模型,由tensorflow,由训练。 产品特点 速度,在nvidia GTX1080... Tensorflow对象检测API(请遵循官方安装说明,否则,我不能
教你一步步使用实现TensorFlow 进行对象检测
DT程序员的博客
05-30 1349
我们将学习如何使用 TensorFlow Hub 预训练模型执行对象检测
使用TensorFlow一步步进行目标检测(1)
云水木石
07-26 1万+
目标检测(Object Detection)是人工智能最基础的应用,不论是我们常见的人脸识别,还是高大上的自动驾驶,都离不开目标检测。要从一幅复杂的画面识别出物体或人物,需要复杂的算法,想想就觉得深奥,不过好在有TensorFlow这样的框架,具有强大的目标检测API,让没有机器学习背景的人也可以快速构建和部署功能强大的图像识别软件。 本系列文章就是来探讨如何借助TensorFlow深度学...
深度学习 -- TensorFlow(项目)验证码生成与识别(多任务学习)
great_yzl的博客
11-02 5375
目录 基础理论 一、生成验证码数据集 1、生成验证码训练集 1-0、判断文件夹是否为空 1-1、创建字符集(数字、大小写英文字母) 1-2、随机生成验证码(1000个,长度为4) 2、生成验证码测试集 代码 二、获取数据(训练集、测试集) 1、获取数据和标签 1-1、获取训练集数据和标签(路径和标签) 1-2、获取测试集数据和标签(路径和标签) 1-3、数据组合(图像路径和标签) 2、打乱数据 3、处理每条数据 4、自定义重复周期和批次大小 5、处理每批数据 6、获取一批
基于opencv检测视频对象的说明文档
06-10
OpenCV是一个广泛使用的开源计算机视觉库,可以用于图像处理、对象识别和机器学习等方面。...除了基于OpenCV的对象检测,还可以使用其他计算机视觉库和深度学习框架来实现视频对象检测,如TensorFlow、PyTorch等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
写文章

热门文章

  • 骂战之后,天才王垠或将加入华为,赵海平怒离职,加入字节跳动! 533911
  • 为什么大公司一定要使用DevOps? 87174
  • 如果有一天程序员再也不忙了 69517
  • 靠纯技术是否能渡过中年危机 34794
  • 工作15年码农总结:学编程难吗?那只是你觉得难! 34274

最新评论

  • 惊呆了!Spring Boot 还能远程调试?

    要钱的大哥: 这个address和配置中的port有什么区别

  • 字节终面:CPU 是如何读写内存的?

    XF_09: cache不是在内存和磁盘之间吗,为什么先查cache再查内存

  • 王者荣耀背后的实时大数据平台用了什么黑科技?

    「已注销」: 真厉害 好详细 问一下作者 想要实现王者荣耀对局的实时评分 能做出来吗

  • 避雷快手!确认面试通过,提交银行流水和个人信息后,被告知其他人接了offer!...

    2401_84730596: 是这样,收集了流水,两周了,也不谈薪,问就是流程中,还要问其它offer情况,我想说,你们公司四轮技术面是啥也没结论吗,还要看其他公司的offer给钱,自己觉得自己面试水平低吗,感觉有点渣男行为

  • 一份两年前一个月的工作经历没写在简历上,背调前主动坦白,却被背调公司亮了红灯,到手的offer没了!...

    2401_84488984: 全景求是管理顾问公司就是干这个的。我老公三年前有一家工作20多天的公司简历没写,进行私密信息调查时,我老公跟它们说漏了一个月如果你们觉得有问题我就不把工资账单、社保记录、缴税信息还有前两家公司的领导信息发给你们了。他们说没事你发吧,offer 也发了。最后还是因为这不到一个月的入职信息li q n红灯。

大家在看

  • java 格式化时间 295
  • 工业无线网关在实际生产中的应用效果和价值-天拓四方
  • 大模型面试看完这些,我直接进入字节了 970
  • 基于Java+SpringBoot+Mysql实现的旅游酒店管理系统设计与实现
  • TON: 引领区块链革命,有望成为下一个十亿级用户公链巨头 275

最新文章

  • 腾讯新闻推荐架构升级:2 年、 300w行代码的涅槃之旅
  • 春晚直播稳定性保障实践
  • Git还能这样用?一文看懂Git最佳实践!
2024
06月 4篇
04月 6篇
03月 13篇
02月 11篇
01月 13篇
2023年496篇
2022年598篇
2021年1467篇
2020年1429篇
2019年868篇
2018年272篇
2017年24篇

目录

目录

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值

聚圣源男孩起名带宇的名字软件企业取名起名大全海阔凭鱼跃杂诗陶渊明城池营垒小说纲手对鸣人的惩罚1的张姓的怎么起名武汉易贷网淮北起名馆有哪些天蝎座运势斗破苍穹番外起名字金木水火土怎么配好钟易轩起名用歆字寓意好的吗斧钺汤镬惠崇春江晚景的古诗群魔乱舞3.5隐藏造纸公司起名大全所有起名大全男孩姓庄起什么名字好的景观起名翠叠园善辈起名科技设备公司起名田起名鼠标连点udietoo修改器北京击剑俱乐部日杂百货店面起名大全无法拥抱的你电视剧淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻让美丽中国“从细节出发”清明节放假3天调休1天男孩疑遭霸凌 家长讨说法被踢出群国产伟哥去年销售近13亿网友建议重庆地铁不准乘客携带菜筐雅江山火三名扑火人员牺牲系谣言代拍被何赛飞拿着魔杖追着打月嫂回应掌掴婴儿是在赶虫子山西高速一大巴发生事故 已致13死高中生被打伤下体休学 邯郸通报李梦为奥运任务婉拒WNBA邀请19岁小伙救下5人后溺亡 多方发声王树国3次鞠躬告别西交大师生单亲妈妈陷入热恋 14岁儿子报警315晚会后胖东来又人满为患了倪萍分享减重40斤方法王楚钦登顶三项第一今日春分两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?周杰伦一审败诉网易房客欠租失踪 房东直发愁男子持台球杆殴打2名女店员被抓男子被猫抓伤后确诊“猫抓病”“重生之我在北大当嫡校长”槽头肉企业被曝光前生意红火男孩8年未见母亲被告知被遗忘恒大被罚41.75亿到底怎么缴网友洛杉矶偶遇贾玲杨倩无缘巴黎奥运张立群任西安交通大学校长黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发妈妈回应孩子在校撞护栏坠楼考生莫言也上北大硕士复试名单了韩国首次吊销离岗医生执照奥巴马现身唐宁街 黑色着装引猜测沈阳一轿车冲入人行道致3死2伤阿根廷将发行1万与2万面值的纸币外国人感慨凌晨的中国很安全男子被流浪猫绊倒 投喂者赔24万手机成瘾是影响睡眠质量重要因素春分“立蛋”成功率更高?胖东来员工每周单休无小长假“开封王婆”爆火:促成四五十对专家建议不必谈骨泥色变浙江一高校内汽车冲撞行人 多人受伤许家印被限制高消费

聚圣源 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化