Home sess.run() by Tensorflow slower than hog.detectMultiscale by OpenCV?
Reply: 0

sess.run() by Tensorflow slower than hog.detectMultiscale by OpenCV?

user1780 Published in July 21, 2018, 11:29 pm

The sess.run() function by the Tensorflow object detection module takes about 2.5 seconds to detect bounding bozes in a 600x600 image while the object detection function by the HOG desctiptor offered by OpenCV takes 0.270 seconds. How's that possible? How can I speed up this code?

def run(image, detection_graph):

    with detection_graph.as_default():
        with tf.Session(graph=detection_graph) as sess:
            # Definite input and output Tensors for detection_graph
            image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
            # Each box represents a part of the image where a particular object was detected.
            detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
            # Each score represent how level of confidence for each of the objects.
            # Score is shown on the result image, together with the class label.
            detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
            detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
            num_detections = detection_graph.get_tensor_by_name('num_detections:0')

            # the array based representation of the image will be used later in order to prepare the
            # result image with boxes and labels on it.
            image_np = image
            # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
            image_np_expanded = np.expand_dims(image_np, axis=0)
            # Actual detection.
            (boxes, scores) = sess.run(
              [detection_boxes, detection_scores],
              feed_dict={image_tensor: image_np_expanded})

            return boxes[0], scores[0]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.56571 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO