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