Skip to content

Commit 021e61c

Browse files
committed
Update submodule models and load CNN for odbjdet just once
1 parent 9a7db67 commit 021e61c

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

models

Submodule models updated 1480 files

project/aat/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Tensorflow Graph load
2+
import os
3+
import tensorflow as tf
4+
5+
6+
CWD_PATH = os.path.join(os.getenv('FACEREC_APP_DIR', '..'), 'aat')
7+
8+
# Path to frozen detection graph. This is the actual model that is used for the object detection.
9+
MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
10+
# MODEL_NAME = 'faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28'
11+
PATH_TO_CKPT = os.path.join(CWD_PATH, 'object_detection', MODEL_NAME, 'frozen_inference_graph.pb')
12+
13+
_detection_graph = tf.Graph()
14+
with _detection_graph.as_default():
15+
od_graph_def = tf.GraphDef()
16+
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
17+
serialized_graph = fid.read()
18+
od_graph_def.ParseFromString(serialized_graph)
19+
tf.import_graph_def(od_graph_def, name='')

project/aat/tasks.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from django.conf import settings
2323

24+
from aat import _detection_graph, CWD_PATH
2425
from .models import Cascade
2526
from .utils.utils import exec_cmd
2627
import aat.utils.recognizer_utils as recognizer
@@ -143,13 +144,6 @@ def object_detection2(self, video_path, framerate):
143144
log.debug("Cannot open video path {}".format(video_path))
144145
return {'od_error': 'Cannot open video'}
145146

146-
CWD_PATH = os.path.join(os.getenv('FACEREC_APP_DIR', '..'), 'aat')
147-
148-
# Path to frozen detection graph. This is the actual model that is used for the object detection.
149-
MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
150-
# MODEL_NAME = 'faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28'
151-
PATH_TO_CKPT = os.path.join(CWD_PATH, 'object_detection', MODEL_NAME, 'frozen_inference_graph.pb')
152-
153147
# List of the strings that is used to add correct label for each box.
154148
PATH_TO_LABELS = os.path.join(CWD_PATH, 'object_detection', 'data', 'mscoco_label_map.pbtxt')
155149
# PATH_TO_LABELS = os.path.join(CWD_PATH, 'object_detection', 'data', ' oid_bbox_trainable_label_map.pbtxt')
@@ -186,15 +180,9 @@ def object_detection2(self, video_path, framerate):
186180

187181
# frame_with_objects = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
188182
frame_with_objects = frame.copy()
189-
detection_graph = tf.Graph()
190-
with detection_graph.as_default():
191-
od_graph_def = tf.GraphDef()
192-
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
193-
serialized_graph = fid.read()
194-
od_graph_def.ParseFromString(serialized_graph)
195-
tf.import_graph_def(od_graph_def, name='')
196-
197-
sess = tf.Session(graph=detection_graph)
183+
184+
detection_graph = _detection_graph
185+
sess = tf.Session(graph=detection_graph)
198186

199187
# Expand dimensions since the model expects images to have shape:
200188
# [1, None, None, 3]

0 commit comments

Comments
 (0)