I have custom model which is detecting menu item from images. But not in correct order, it picks random not in correct order like in below images. For example, it will detect option 3 first then option 4 and so on, not like option 1 first, then 2, and so on. enter image description here from PIL import Image def mainSection(imagePath): menu_image = Image.open(imagePath) cropped_images = \[\] model_1 = YOLO(r"C:\\Users\\saura\\Desktop\\New Model05-07\\model_1.pt") prediction = model_1.predict(menu_image, verbose=False) for predicted_image in prediction: for section in predicted_image.boxes: x_min, y_min, x_max, y_max, confidence, class_id = section.data\[0\].cpu().numpy() cropped_image_section = menu_image.crop((x_min, y_min, x_max, y_max)) cropped_images.append(cropped_image_section) # Sort cropped images based on x_min and y_min coordinates cropped_images = sorted(cropped_images, key=lambda img: (img.x_min, img.y_min)) return cropped_images Continue reading...