code: from __future__ import division
  
  import argparse
  import logging.config
  import os
  import time
  
  import cv2
  import numpy as np
  import tensorflow.compat.v1 as tf
  tf.disable_v2_behavior()
  
  from utils import cv_utils
  from utils import operations as ops
  from utils import tf_utils
  
  logging.config.fileConfig('logging.ini')
  
  FROZEN_GRAPH_PATH = 'models/ssd_mobilenet_v1/frozen_inference_graph.pb'
  
  SCORE_THRESHOLD = 0.5
  NON_MAX_SUPPRESSION_THRESHOLD = 0.5
  
  
  class ConeDetector:
  
      def __init__(self) -> None:
          #detection_graph = tf_utils.load_model(FROZEN_GRAPH_PATH)
  
          #self.sess =  tf.Session(graph=detection_graph)
          pass
  
      def ispath(path):
          if not os.path.exists(path):
              raise argparse.ArgumentTypeError('No such file or directory: ' + path)
          else:
              return path
  
      def find_cones(self, img, crop_size=None):
          # Read TensorFlow graph
          detection_graph = tf_utils.load_model(FROZEN_GRAPH_PATH)
  
          with tf.Session(graph=detection_graph) as sess:
              tic = time.time()
  
              boxes = []
  
              if crop_size:
                  crop_height = crop_width = crop_size
                  crop_step_vertical = crop_step_horizontal = crop_size - 20
                  crops, crops_coordinates = ops.extract_crops(
                      img, crop_height, crop_width,
                      crop_step_vertical, crop_step_horizontal)
  
                  detection_dict = tf_utils.run_inference_for_batch(crops, sess)
  
                  for box_absolute, boxes_relative in zip(
                          crops_coordinates, detection_dict['detection_boxes']):
                      boxes.extend(ops.get_absolute_boxes(
                          box_absolute,
                          boxes_relative[np.any(boxes_relative, axis=1)]))
  
                  boxes = np.vstack(boxes)
                  boxes = ops.non_max_suppression_fast(
                      boxes, NON_MAX_SUPPRESSION_THRESHOLD)
              else:
                  detection_dict = tf_utils.run_inference_for_batch(
                      np.expand_dims(img, axis=0), sess)
                  boxes = detection_dict['detection_boxes']
                  boxes = boxes[np.any(boxes, axis=2)]
  
              boxes_scores = detection_dict['detection_scores']
              boxes_scores = boxes_scores[np.nonzero(boxes_scores)]
  
              for box, score in zip(boxes, boxes_scores):
                  if score > SCORE_THRESHOLD:
                      ymin, xmin, ymax, xmax = box
                      color_detected_rgb = cv_utils.predominant_rgb_color(
                          img, ymin, xmin, ymax, xmax)
                      text = '{:.2f}'.format(score)
                      cv_utils.add_rectangle_with_text(
                          img, ymin, xmin, ymax, xmax,
                          color_detected_rgb, text)
  
              toc = time.time()
              processing_time_ms = (toc - tic) * 1000
              logging.debug('Detected {} objects in {:.2f} ms'.format(
                  len(boxes), processing_time_ms))
  
              return img
  
apis: numpy.vstack tensorflow.compat.v1.Session numpy.any numpy.expand_dims tensorflow.compat.v1.disable_v2_behavior numpy.nonzero