Skip to content

Commit

Permalink
v.1.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sglvladi committed Apr 4, 2020
1 parent e732ab9 commit da422b4
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 226 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 16 additions & 13 deletions docs/source/camera.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Detect Objects Using Your Webcam

Hereby you can find an example which allows you to use your camera to generate a video stream, based on which you can perform object_detection.

To run the example, simply create a new file under ``<PATH_TO_TF>/TensorFlow/models/research/object_detection`` and paste the code below.

.. code-block:: python
import numpy as np
Expand All @@ -18,8 +20,8 @@ Hereby you can find an example which allows you to use your camera to generate a
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
from utils import label_map_util
from utils import visualization_utils as vis_util
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
# Define the video stream
cap = cv2.VideoCapture(0) # Change only if you have more than one webcams
Expand All @@ -40,20 +42,22 @@ Hereby you can find an example which allows you to use your camera to generate a
NUM_CLASSES = 90
# Download Model
opener = urllib.request.URLopener()
opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
tar_file = tarfile.open(MODEL_FILE)
for file in tar_file.getmembers():
file_name = os.path.basename(file.name)
if 'frozen_inference_graph.pb' in file_name:
tar_file.extract(file, os.getcwd())
if not os.path.exists(os.path.join(os.getcwd(), MODEL_FILE)):
print("Downloading model")
opener = urllib.request.URLopener()
opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
tar_file = tarfile.open(MODEL_FILE)
for file in tar_file.getmembers():
file_name = os.path.basename(file.name)
if 'frozen_inference_graph.pb' in file_name:
tar_file.extract(file, os.getcwd())
# Load a (frozen) Tensorflow model into memory.
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
od_graph_def = tf.compat.v1.GraphDef()
with tf.io.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
Expand All @@ -76,9 +80,8 @@ Hereby you can find an example which allows you to use your camera to generate a
# Detection
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
with tf.compat.v1.Session(graph=detection_graph) as sess:
while True:
# Read frame from camera
ret, image_np = cap.read()
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
Expand Down
20 changes: 13 additions & 7 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@
TensorFlow Object Detection API tutorial
============================================

.. important:: This tutorial is intended for TensorFlow 1.14, which (at the time of writing this tutorial) is the latest stable version before TensorFlow 2.x.

Tensorflow 1.15 has also been released, but seems to be exhibiting `instability issues <https://github.com/tensorflow/models/issues/7640>`_.

A version for Tensorflow 1.9 can be found `here <https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/v1.9.1/>`_.

A version for Tensorflow 2.x is in the making and a link will be added here when ready.

This is a step-by-step tutorial/guide to setting up and using TensorFlow's Object Detection API to perform, namely, object detection in images/video.

The software tools which we shall use throughout this tutorial are listed in the table below:

+---------------------------------------------+
| Target Software versions |
+==============+==============================+
| OS | Windows, Linux [*]_ |
| OS | Windows, Linux |
+--------------+------------------------------+
| Python | 3.6 |
| Python | 3.7 |
+--------------+------------------------------+
| TensorFlow | 1.9 |
| TensorFlow | 1.14 |
+--------------+------------------------------+
| CUDA Toolkit | v9.0 |
| CUDA Toolkit | 10.0 |
+--------------+------------------------------+
| CuDNN | v7.0.5 |
| CuDNN | 7.6.5 |
+--------------+------------------------------+
| Anaconda | Python 3.7 (Optional) |
+--------------+------------------------------+

.. [*] Even though this tutorial is mostly based (and properly tested) on Windows 10, information is also provided for Linux systems.
.. toctree::
:maxdepth: 4
:caption: Contents:
Expand Down
Loading

0 comments on commit da422b4

Please sign in to comment.