Predictions with `inference` library are different from Visualize page

I built a local/offline prediction app using the ONNX weights and the inference Python library but the predictions are significantly different from those on the “Visualize” page.

Example: Red = my app

Anything I’m doing wrong?

Code of the prediction app:

import os

import inference
import streamlit as st
from PIL import Image, ImageDraw

model = inference.get_model(...)


# Function to draw bounding boxes on image
def draw_boxes(image, boxes):
    image = image.copy()
    img_draw = ImageDraw.Draw(image)
    for box in boxes:
        x0 = box.x - box.width / 2
        y0 = box.y - box.height / 2
        x1 = box.x + box.width / 2
        y1 = box.y + box.height / 2
        img_draw.rectangle((x0, y0, x1, y1), outline="red", width=3)
        img_draw.text((x0, y0), f"{box.confidence:.03f}", font_size=16, fill="red")
    return image


# Streamlit app
def main():
    st.title("Handwriting Detection")

    uploaded_images = st.file_uploader(
        "Images to annotate", type=["jpg", "jpeg", "png"], accept_multiple_files=True
    )
    uploaded_images = [Image.open(img).convert("RGB") for img in uploaded_images]

    for img in uploaded_images:
        pred = model.infer(img)[0]
        image_with_boxes = draw_boxes(img, pred.predictions)
        st.image(image_with_boxes, use_column_width=True)


if __name__ == "__main__":
    main()

The answer might be in this post Locally depoloyed model gives different result from the hosted one - #2 by camerayuhang

@Emily in that thread you say that users should tile before sending to the inference server/model. I wanted to understand how tiling is done by Roboflow and it looks like it is done server-side. Could you please refer to the piece of code that does the tiling and un-tiling? Or is this proprietary code?

Thank you!

Hey @Jonas_Haag

Are you using tiling as a preprocessing step while creating your dataset? If so, you can use the Inference Slicer utility from Supervision to replicate tiling. We also have this blog post on using SAHI (which is a tiling based inference technique)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.