1
votes

I am referring to Tensorflow Object Detection API (https://github.com/tensorflow/models/tree/master/research/object_detection): Heres the IPython notebook for the detection code I am using (https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb). In this file the output values are set to draw boxes for probability greater than 50% Detection code:

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')

    #myFile = open('example2.csv', 'w')
    i=0
    #boxeslist=[]
    new_boxes = []
    for image_path in TEST_IMAGE_PATHS:
      image = Image.open(image_path)
      # 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 = load_image_into_numpy_array(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, classes, num) = sess.run(
          [detection_boxes, detection_scores, detection_classes, num_detections],
          feed_dict={image_tensor: image_np_expanded})
      # 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)

      plt.figure(figsize=IMAGE_SIZE)
      plt.imshow(image_np)

How do I change the code so that it outputs boxes around object for > 10% probability

2

2 Answers

6
votes

Should be quite easy.

As you can see, this tutorial calls the function 'vis_util.visualize_boxes_and_labels_on_image_array' whose arguments are:

image
boxes
classes
scores
category_index
use_normalized_coordinates
line_thickness

If search inside the file: 'research/object_detection/utilis/visualization_utils.py' you can find that function and see that there are other arguments that you can set.

Among these you can find: min_score_tresh that is setted to .5

If you set:

min_score_tresh=.1

should obtain the desired result.

Be careful, cause will be sh

0
votes

The simple way is to add "min_score_thresh" in "vis_util.visualize_boxes_and_labels_on_image_array" to set the detection threshold:

      # 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,
          min_score_thresh=.1) # <<======== Add this line for threshold