You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/examples/plot_object_detection_checkpoint.py
+92-99Lines changed: 92 additions & 99 deletions
Original file line number
Diff line number
Diff line change
@@ -1,70 +1,54 @@
1
1
#!/usr/bin/env python
2
2
# coding: utf-8
3
3
"""
4
-
Object Detection Test
5
-
=====================
4
+
Object Detection From TF2 Checkpoint
5
+
====================================
6
6
"""
7
7
8
8
# %%
9
-
# This demo will take you through the steps of running an "out-of-the-box" detection model on a
10
-
# collection of images.
11
-
12
-
# %%
13
-
# Create the data directory
14
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~
15
-
# The snippet shown below will create the ``data`` directory where all our data will be stored. The
16
-
# code will create a directory structure as shown bellow:
17
-
#
18
-
# .. code-block:: bash
19
-
#
20
-
# data
21
-
# ├── images
22
-
# └── models
23
-
#
24
-
# where the ``images`` folder will contain the downlaoded test images, while ``models`` will
25
-
# contain the downloaded models.
26
-
importos
27
-
28
-
DATA_DIR=os.path.join(os.getcwd(), 'data')
29
-
IMAGES_DIR=os.path.join(DATA_DIR, 'images')
30
-
MODELS_DIR=os.path.join(DATA_DIR, 'models')
31
-
fordirin [DATA_DIR, IMAGES_DIR, MODELS_DIR]:
32
-
ifnotos.path.exists(dir):
33
-
os.mkdir(dir)
9
+
# This demo will take you through the steps of running an "out-of-the-box" TensorFlow 2 compatible
10
+
# detection model on a collection of images. More specifically, in this example we will be using
11
+
# the `Checkpoint Format <https://www.tensorflow.org/guide/checkpoint>`__ to load the model.
34
12
35
13
# %%
36
14
# Download the test images
37
15
# ~~~~~~~~~~~~~~~~~~~~~~~~
38
16
# First we will download the images that we will use throughout this tutorial. The code snippet
39
17
# shown bellow will download the test images from the `TensorFlow Model Garden <https://github.com/tensorflow/models/tree/master/research/object_detection/test_images>`_
40
18
# and save them inside the ``data/images`` folder.
# The code snippet shown below is used to download the object detection model checkpoint file,
62
-
# as well as the labels file (.pbtxt) which contains a list of strings used to add the correct
63
-
# label to each detection (e.g. person). Once downloaded the files will be stored under the
64
-
# ``data/models`` folder.
65
-
#
66
-
# The particular detection algorithm we will use is the `CenterNet HourGlass104 1024x1024`. More
67
-
# models can be found in the `TensorFlow 2 Detection Model Zoo <https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md>`_.
49
+
# The code snippet shown below is used to download the pre-trained object detection model we shall
50
+
# use to perform inference. The particular detection algorithm we will use is the
51
+
# `CenterNet HourGlass104 1024x1024`. More models can be found in the `TensorFlow 2 Detection Model Zoo <https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md>`_.
68
52
# To use a different model you will need the URL name of the specific model. This can be done as
69
53
# follows:
70
54
#
@@ -76,62 +60,63 @@
76
60
#
77
61
# For example, the download link for the model used below is: ``download.tensorflow.org/models/object_detection/tf2/20200711/centernet_hg104_1024x1024_coco17_tpu-32.tar.gz``
print('Done! Took {} seconds'.format(elapsed_time))
147
135
148
136
# %%
149
137
# Load label map data (for plotting)
@@ -172,7 +160,6 @@ def detect_fn(image):
172
160
# * Print out `detections['detection_boxes']` and try to match the box locations to the boxes in the image. Notice that coordinates are given in normalized form (i.e., in the interval [0, 1]).
173
161
# * Set ``min_score_thresh`` to other values (between 0 and 1) to allow more detections in or to filter out more detections.
0 commit comments