text: # AUTOGENERATED! DO NOT EDIT! File to edit: creating_two_detector_results.ipynb (unless otherwise specified).
  
  __all__ = ['load_image', 'get_n_best_bbs', 'get_bbs', 'plot', 'get_bb_crop', 'get_bb_crops', 'get_foods_and_recipes']
  
  # Cell
  import tensorflow as tf
  from tensorflow.keras.models import load_model
  from pathlib import Path
  from PIL import Image
  import os
  import cv2
  import numpy as np
  from tqdm.notebook import tqdm
  
  from .bbox import *
  from fastcore.foundation import *
  from matplotlib import pyplot as plt
  
  from fastcore.test import *
  
  
  # Cell
  def load_image(img_path):
      img = tf.io.read_file(str(img_path))
      img = tf.image.decode_jpeg(img, channels=3)
      return img
  
  def get_n_best_bbs(bbs, scrs, n):
      x = list(zip(bbs,scrs))
      x = sorted(x, key=lambda x: x[1], reverse=True)[:n]
      bbs, scrs = tuple(zip(*x))
      return bbs, scrs
  
  def get_bbs(img, model, threshold=0.5, n_best=None, in_absolute_coords=False):
      h, w, _ = img.shape
      img = cv2.resize(img, (400,400), cv2.INTER_AREA)
      out = model(img[None])
      scrs, bbs = out['detection_scores'].numpy(), out['detection_boxes'].numpy()
  
      bbs, scrs = bbs[0], scrs[0]
      bbs = L(BBox(bb, bb_format='array_coords') for bb in bbs)
      if in_absolute_coords: bbs = L(bb.to_absolute(w, h) for bb in bbs)
  
      if n_best: return get_n_best_bbs(bbs, scrs, n_best)
      else:      return bbs[scrs > threshold], scrs[scrs > threshold]
  
  
  # Cell
  def plot(imgs):
      if isinstance(imgs, np.ndarray):
          fig, ax = plt.subplots(figsize=(12, 12))
          ax.imshow(imgs)
      else:
          n_imgs = len(imgs)
          fig, axs = plt.subplots(ncols=n_imgs, figsize=(12, 12))
          for ax, img in zip(axs, imgs): ax.imshow(img)
  
  # Cell
  def get_bb_crop(img, bb):
      height, width, _ = img.shape
      bb.to_absolute(width, height)
      x1, y1, x2, y2 = bb
      return img[y1:y2, x1:x2]
  
  def get_bb_crops(img, bbs): return [get_bb_crop(img, bb) for bb in bbs]
  
  def get_foods_and_recipes(img, det1, det2, multi_piatto_dim=700):
      bbs, scrs = get_bbs(img, det1)
      foods = get_bb_crops(img, bbs)
      foods_rcps = []
      for food in foods:
          h, w, _ = food.shape
          if h > multi_piatto_dim and w > multi_piatto_dim:
              rcp_bbs, scrs = get_bbs(food, det2)
              rcps = get_bb_crops(food, rcp_bbs)
              foods_rcps.append((food, rcps))
          else:
              foods_rcps.append((food,))
      return foods_rcps
  
  # Cell
  import tensorflow as tf
  from tensorflow.keras.models import load_model
  from pathlib import Path
  from PIL import Image
  import os
  import cv2
  import numpy as np
  from tqdm.notebook import tqdm
  
  from xml.etree.ElementTree import Element, SubElement, tostring
  import pprint
  from xml.dom.minidom import parseString
  
  from .bbox import *
  from .inference import *
  
  from fastcore.test import *