Petri Dish YOLO ONNX

YOLO object detection model for detecting round Petri dishes in camera images.

Model Details

  • Model file: bestnew.onnx
  • Format: ONNX
  • Task: Object detection
  • Object class: Petri dish
  • Inference runtime: ONNX Runtime
  • Recommended provider: CPUExecutionProvider

What the Model Does

The model takes an image as input and returns bounding-box detections for Petri dishes.

It performs Petri dish detection only.

Input

The model expects one image frame.

Input tensor

Shape: [1, 3, H, W]
Type: float32
Range: 0.0 to 1.0
Layout: NCHW

Where:

  • 1 is the batch size
  • 3 is the number of image channels
  • H and W are the model input height and width

The input size should be read from the ONNX model:

input_size = session.get_inputs()[0].shape[2]

Preprocessing

The image should be resized with aspect-ratio preservation and padded to a square input canvas.

import cv2
import numpy as np
def preprocess(img: np.ndarray, input_size: int):
    h, w = img.shape[:2]
    scale = input_size / max(h, w)
    nh, nw = int(h * scale), int(w * scale)
    canvas = np.full((input_size, input_size, 3), 114, dtype=np.uint8)
    top = (input_size - nh) // 2
    left = (input_size - nw) // 2
    resized = cv2.resize(img, (nw, nh))
    canvas[top:top + nh, left:left + nw] = resized
    blob = canvas.astype(np.float32) / 255.0
    blob = np.transpose(blob, (2, 0, 1))[None]
    return blob, scale, left, top, w, h

Output

The model outputs YOLO-style detections.

Each raw detection has the format:

[x_center, y_center, width, height, confidence]

Where:

  • x_center is the bounding-box centre X coordinate
  • y_center is the bounding-box centre Y coordinate
  • width is the bounding-box width
  • height is the bounding-box height
  • confidence is the detection confidence score

Postprocessing

After inference, detections should be:

  1. Filtered by confidence
  2. Converted from centre-format boxes to corner-format boxes
  3. Mapped back to the original image coordinate space
  4. Filtered with Non-Maximum Suppression

Recommended thresholds:

CONF_THRES = 0.75
IOU_THRES = 0.45

Example postprocessing:

import cv2
def postprocess(pred, scale, dx, dy, orig_w, orig_h):
    boxes = []
    scores = []
    for det in pred[0][0]:
        conf = float(det[4])
        if conf < CONF_THRES:
            continue
        x, y, w, h = det[:4]
        x1 = (x - w / 2 - dx) / scale
        y1 = (y - h / 2 - dy) / scale
        x2 = (x + w / 2 - dx) / scale
        y2 = (y + h / 2 - dy) / scale
        boxes.append([x1, y1, x2, y2])
        scores.append(conf)
    if not boxes:
        return []
    rects = [
        [int(x1), int(y1), int(x2 - x1), int(y2 - y1)]
        for x1, y1, x2, y2 in boxes
    ]
    idx = cv2.dnn.NMSBoxes(
        rects,
        scores,
        CONF_THRES,
        IOU_THRES
    )
    if idx is None or len(idx) == 0:
        return []
    return [
        (
            boxes[i][0],
            boxes[i][1],
            boxes[i][2],
            boxes[i][3],
            scores[i]
        )
        for i in idx.flatten()
    ]

Final detections are returned as:

[x1, y1, x2, y2, confidence]

Where:

  • x1, y1 are the top-left bounding-box coordinates
  • x2, y2 are the bottom-right bounding-box coordinates
  • confidence is the model confidence score

Example Inference

import cv2
import numpy as np
import onnxruntime as ort
CONF_THRES = 0.75
IOU_THRES = 0.45
model_path = "bestnew.onnx"
image_path = "example.jpg"
session = ort.InferenceSession(
    model_path,
    providers=["CPUExecutionProvider"]
)
input_name = session.get_inputs()[0].name
input_size = session.get_inputs()[0].shape[2]
image = cv2.imread(image_path)
blob, scale, dx, dy, orig_w, orig_h = preprocess(image, input_size)
predictions = session.run(
    None,
    {input_name: blob}
)
detections = postprocess(
    predictions,
    scale,
    dx,
    dy,
    orig_w,
    orig_h
)
print(detections)

Example detection output:

[
    [124.6, 88.3, 412.9, 376.4, 0.93],
    [530.1, 91.5, 816.2, 379.8, 0.89]
]

Output Meaning

Each detection represents one detected Petri dish in the input image.

[x1, y1, x2, y2, confidence]

Example:

[124.6, 88.3, 412.9, 376.4, 0.93]

This means:

  • Top-left corner: (124.6, 88.3)
  • Bottom-right corner: (412.9, 376.4)
  • Confidence: 0.93

Intended Use

This model is intended for detecting Petri dishes in camera images and returning their bounding-box locations.

Limitations

  • The model only detects Petri dishes.
  • Detection quality depends on image quality, camera angle, lighting, occlusion, and similarity to the training data.
  • Postprocessing thresholds may need adjustment for different camera setups.
  • The model output should be validated in the target imaging environment before production use.

Citation

If you use this model, please cite this Hugging Face repository.

@misc{rohan_r_2026,
    author       = { Rohan R },
    title        = { petri_dish_yolo (Revision 0ab5b88) },
    year         = 2026,
    url          = { https://huggingface.co/rotsl/petri_dish_yolo },
    doi          = { 10.57967/hf/9098 },
    publisher    = { Hugging Face }
}

License

MIT @ Rohan R, 2026

Downloads last month
8
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for rotsl/petri_dish_yolo

Quantized
(42)
this model