parameters: (inference_output, categories, threshold, anchor_boxes)
return_statement: return regions
docstring: Returns an array of Region instances that represent detected objects
      and their locations.
  
      `inference_output` must be a tensor in the shape of the output of the
      network.
  
      `categories` is a list of categories that represent the type of objects to
      be detected.
  
      `threshold` is the minimum probability of the presence of an object and
      that the object is of a specific type, i.e., P(category|object) >=
      `threshold`.
  
      `anchor_boxes` is the list of anchor boxes that are used to augment the
      bounding boxes.
docstring_summary: Returns an array of Region instances that represent detected objects
      and their locations.
docstring_tokens: Returns an array of Region instances that represent detected objects and their locations .
function: def get_regions(inference_output, categories, threshold, anchor_boxes):
      """Returns an array of Region instances that represent detected objects
      and their locations.
  
      `inference_output` must be a tensor in the shape of the output of the
      network.
  
      `categories` is a list of categories that represent the type of objects to
      be detected.
  
      `threshold` is the minimum probability of the presence of an object and
      that the object is of a specific type, i.e., P(category|object) >=
      `threshold`.
  
      `anchor_boxes` is the list of anchor boxes that are used to augment the
      bounding boxes.
      """
  
      regions = []
      shape = inference_output.shape
      # four values for the bounding box coordinates plus one for the confidence
      # the rest of the values are the probabilities for the individual
      # categories
      box_size = 5 + len(categories)
      num_boxes = shape[2] // box_size
      for i, j, c in product(range(shape[0]),
                             range(shape[1]),
                             range(num_boxes)):
          # The coordinates and confidence values need to be "unpacked".
          # The order for each region is `[x, y, w, h, c,
          # category probabilities...]`. There are `num_boxes` regions for each
          # `i, j` coordinate pair.
          box_offset = c * box_size
          # The X and Y values need to have sigmoid activation applied
          predicted_x = sigmoid(inference_output[i, j, box_offset + 0])
          predicted_y = sigmoid(inference_output[i, j, box_offset + 1])
          # The width and height need to be exponentiated
          predicted_width = np.exp(inference_output[i, j, box_offset + 2])
          predicted_height = np.exp(inference_output[i, j, box_offset + 3])
          predicted_confidence = inference_output[i, j, box_offset + 4]
  
          # Get the final normalized values for the coordinates of the bounding
          # box
          x = (j + predicted_x) / shape[0]
          y = (i + predicted_y) / shape[1]
          w = predicted_width * anchor_boxes[2 * c + 0] / shape[0]
          h = predicted_height * anchor_boxes[2 * c + 1] / shape[1]
          confidence = predicted_confidence
  
          # The `category_scores` have not had softmax applied to them, so just
          # apply softmax and find the index of the largest value and get the
          # corresponding category label.
          category_scores = softmax(inference_output[i,
                                                     j,
                                                     box_offset + 5 :
                                                     box_offset + box_size])
          category_index = np.argmax(category_scores)
          probability = confidence * category_scores[category_index]
  
          # Only add to the list of returned regions if the probability is
          # greater than the threshold
          if probability > threshold:
              regions.append(Region(categories[category_index], probability,
                                    (x - (w/2), y - (h/2), w, h)))
      return regions
function_tokens: def get_regions ( inference_output , categories , threshold , anchor_boxes ) : regions = [ ] shape = inference_output . shape # four values for the bounding box coordinates plus one for the confidence # the rest of the values are the probabilities for the individual # categories box_size = 5 + len ( categories ) num_boxes = shape [ 2 ] // box_size for i , j , c in product ( range ( shape [ 0 ] ) , range ( shape [ 1 ] ) , range ( num_boxes ) ) : # The coordinates and confidence values need to be "unpacked". # The order for each region is `[x, y, w, h, c, # category probabilities...]`. There are `num_boxes` regions for each # `i, j` coordinate pair. box_offset = c * box_size # The X and Y values need to have sigmoid activation applied predicted_x = sigmoid ( inference_output [ i , j , box_offset + 0 ] ) predicted_y = sigmoid ( inference_output [ i , j , box_offset + 1 ] ) # The width and height need to be exponentiated predicted_width = np . exp ( inference_output [ i , j , box_offset + 2 ] ) predicted_height = np . exp ( inference_output [ i , j , box_offset + 3 ] ) predicted_confidence = inference_output [ i , j , box_offset + 4 ] # Get the final normalized values for the coordinates of the bounding # box x = ( j + predicted_x ) / shape [ 0 ] y = ( i + predicted_y ) / shape [ 1 ] w = predicted_width * anchor_boxes [ 2 * c + 0 ] / shape [ 0 ] h = predicted_height * anchor_boxes [ 2 * c + 1 ] / shape [ 1 ] confidence = predicted_confidence # The `category_scores` have not had softmax applied to them, so just # apply softmax and find the index of the largest value and get the # corresponding category label. category_scores = softmax ( inference_output [ i , j , box_offset + 5 : box_offset + box_size ] ) category_index = np . argmax ( category_scores ) probability = confidence * category_scores [ category_index ] # Only add to the list of returned regions if the probability is # greater than the threshold if probability > threshold : regions . append ( Region ( categories [ category_index ] , probability , ( x - ( w / 2 ) , y - ( h / 2 ) , w , h ) ) ) return regions