run_inference_for_single_image(image, graph) - Tensorflow, object detection

后端 未结 3 1550
有刺的猬
有刺的猬 2021-01-06 20:47

In reference to object_detection_tutorial.ipynb. I am wondering if its possible to run for all the images in a directory.

Rather than writing a for loop and running

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 21:40

    As you know, 'run_inference_for_single_image' method create each time. If you wanna inference for multiple images, you should change code like,

    • Method Call

      images = []
      for f in files:
        if f.lower().endswith(('.png', '.jpg', '.jpeg')):
          image_path = files_dir + '/' + f
          image =  .... // Read image etc.
          images.append(image)
          output_dicts = run_inference_for_multiple_images(images, detection_graph)
      
    • run_inference_for_multiple_images

      def run_inference_for_multiple_images(images, grapg):
        with graph.as_default():
          with tf.Session() as sess:
            output_dicts = []
      
            for index, image in enumerate(images):
              ... same as inferencing for single image
      
               output_dicts.append(output_dict)
      
         return output_dicts
      

    This code will be performed without creating tf.session each time but once.

提交回复
热议问题