Время на обработку серии изображений одновременно почти равно последовательной обработке - PullRequest
0 голосов
/ 17 мая 2018

Системная информация

- What is the top-level directory of the model you are using: object_detection
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No, just a small tweak for inference
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Ubuntu 16.04
- TensorFlow installed from (source or binary): conda
- TensorFlow version (use command below): 1.4.0
- GPU model and memory: Nvidia GTX 1060 6GB

Проблема:

Теоретически, выполнение вывода для пакета из n изображений (n - максимальное количество изображений, которое может вместить графический процессор), и 1 изображение должно занимать почти одинаковое время. Я пытаюсь сделать пакетный вывод, используя faster_rcnn_inception_v2_coco's frozen_inference_graph. Визуализация замороженного графика вывода показывает, что вход имеет форму (Нет, Нет, Нет, 3), поэтому я могу безопасно обрабатывать пакет изображений одновременно. screenshot 15. Но когда я попытался обработать пакет из 1 изображения против пакета из 10 изображений, я не получил то же самое время вывода

Последний блок в учебнике по обнаружению объектов Ipython Notebook изменяется следующим образом, и используется график faster_rcnn_inception_v2_coco.

import cv2
itr_num = 10
batch_size = 1
inference_times = []
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')
        for im_num in range(itr_num):
            images = [cv2.cvtColor(cv2.imread(TEST_IMAGE_PATHS[1]),cv2.COLOR_BGR2RGB) for _ in range(batch_size)]
            images = np.array(images)
            print(images.shape)
            assert len(images) == batch_size, "lists are not equal {}, {}".format(len(images),batch_size)
            start_time = time.time()
            (boxes, scores, classes, num) = sess.run(
              [detection_boxes, detection_scores, detection_classes, num_detections],
              feed_dict={image_tensor: images})
            print("The time taken for image set{} is {} secs".format(im_num+1,time.time()-start_time))
            inference_times.append(time.time()-start_time)
            # Visualization of the results of a detection.
#             vis_util.visualize_boxes_and_labels_on_image_array(
#               image_np,
#               np.squeeze(boxes),
#               np.squeeze(classes).astype(np.int32),
#               np.squeeze(scores),
#               category_index,
#               use_normalized_coordinates=True,
#               line_thickness=8)

inference_times = np.array(inference_times[1:])
print("average time for {} (images excluding the first image) is {}".format(itr_num-1,inference_times.mean()))

Вывод для batch_size = 1

(1, 900, 1352, 3)
The time taken for image set1 is 2.029768228530884 secs
(1, 900, 1352, 3)
The time taken for image set2 is 0.12289047241210938 secs
(1, 900, 1352, 3)
The time taken for image set3 is 0.11852574348449707 secs
(1, 900, 1352, 3)
The time taken for image set4 is 0.12165331840515137 secs
(1, 900, 1352, 3)
The time taken for image set5 is 0.11874818801879883 secs
(1, 900, 1352, 3)
The time taken for image set6 is 0.11887550354003906 secs
(1, 900, 1352, 3)
The time taken for image set7 is 0.122528076171875 secs
(1, 900, 1352, 3)
The time taken for image set8 is 0.12240052223205566 secs
(1, 900, 1352, 3)
The time taken for image set9 is 0.1199343204498291 secs
(1, 900, 1352, 3)
The time taken for image set10 is 0.12351012229919434 secs
average time for 9 (images excluding the first image) is 0.12106058332655165

Вывод для batch_size = 10:

(10, 900, 1352, 3)
The time taken for image set1 is 2.459228992462158 secs
(10, 900, 1352, 3)
The time taken for image set2 is 0.9496431350708008 secs
(10, 900, 1352, 3)
The time taken for image set3 is 0.9487781524658203 secs
(10, 900, 1352, 3)
The time taken for image set4 is 0.9454429149627686 secs
(10, 900, 1352, 3)
The time taken for image set5 is 0.9377844333648682 secs
(10, 900, 1352, 3)
The time taken for image set6 is 0.9478261470794678 secs
(10, 900, 1352, 3)
The time taken for image set7 is 0.9489026069641113 secs
(10, 900, 1352, 3)
The time taken for image set8 is 0.9412193298339844 secs
(10, 900, 1352, 3)
The time taken for image set9 is 1.0171809196472168 secs
(10, 900, 1352, 3)
The time taken for image set10 is 0.938474178314209 secs
average time for 9 (images excluding the first image) is 0.9528606202867296

Время, необходимое для обработки 10 изображений вместе, ~ в 10 раз больше, чем для обработки одного изображения. Этого не должно быть. Что мне здесь не хватает? Благодаря.

Мой вопрос: почему Tensorflow занимает 0,95 сек, что примерно равно 10 * 0,1 (время обработки одного изображения) с при выполнении пакетной обработки? не должна ли партия из 10 изображений также занимать 0,1 с? (из-за параллельная обработка?)

PS:

Время, затрачиваемое на вывод 1 изображения, почти вдвое больше, чем указано в эталонном образце зоопарка (0,058).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...