Class Detection Issue with YOLOv8 Model - Inconsistent Results Across Environments

Hello Roboflow Community,

I’m facing a strange issue with my YOLOv8 model and need your expertise.

Context:

  • Model: Custom YOLOv8 object detection model.
  • Framework: Ultralytics YOLO (integrated with Roboflow).
  • Issue: When running inference locally (CPU) or on a VPS (no GPU), the model fails to detect certain classes/labels. However, the same model works perfectly:
    • In Roboflow’s workflow (web interface).
    • On Google Colab (GPU environment).

Example:
For the same image:

  • Local/VPS Script Output: Only detects next_button2.
  • Roboflow/Colab Output: Detects both next_button2 and email_field2.

What I’ve Tried:

  1. Verified model weights and dataset consistency.
  2. Tested identical images across all environments.
  3. Simplified inference code (no custom post-processing).

Code Used:

Google Colab (Works Fine):

from ultralytics import YOLO  
import requests  
from PIL import Image  
from io import BytesIO  
import matplotlib.pyplot as plt  
import os  

# Load YOLOv8 model  
best_weights = "runs/detect/model_connect2/weights/best.pt"  
trained_model = YOLO(best_weights)  

# Test image URL  
image_url = ""  

# Download and predict  
response = requests.get(image_url, headers={"User-Agent": "Mozilla/5.0"})  
image = Image.open(BytesIO(response.content)).convert("RGB")  
results = trained_model(image)  

# Display results  
plt.imshow(results[0].plot())  
plt.axis('off')  
plt.show()  

Output:

0: 384x640 1 email_field2, 1 next_button2, 89.6ms  
Speed: 3.4ms preprocess, 89.6ms inference, 1.0ms postprocess per image at shape (1, 3, 384, 640)  

VPS Script (Fails to Detect email_field2):

import sys  
import json  
import os  
import contextlib  
from ultralytics import YOLO  

# Suppress logs  
@contextlib.contextmanager  
def suppress_stdout_stderr():  
    with open(os.devnull, 'w') as fnull:  
        old_stdout, old_stderr = sys.stdout, sys.stderr  
        sys.stdout, sys.stderr = fnull, fnull  
        try:  
            yield  
        finally:  
            sys.stdout, sys.stderr = old_stdout, old_stderr  

# Load model  
with suppress_stdout_stderr():  
    model = YOLO("/home/root1/yo/best.pt")  

# Run inference  
image_path = sys.argv[1]  
with suppress_stdout_stderr():  
    results = model(image_path)  

# Prepare JSON output  
detections = []  
for result in results:  
    for box in result.boxes:  
        class_id = int(box.cls)  
        class_name = model.names[class_id]  
        x, y, w, h = box.xywh[0].tolist()  
        detections.append({"label": class_name, "x": x, "y": y, "w": w, "h": h})  

# Print JSON  
print(json.dumps(detections))  

Output:

[{"label": "next_button2", "x": 1082.9072265625, "y": 592.21142578125, "w": 109.9459228515625, "h": 36.38958740234375}]  

Additional Details:

  • OS: Windows (local), Ubuntu (VPS).
  • Roboflow Workflow Link: Workflow

Key Questions:

  1. Why does the model fail to detect email_field2 on CPU (local/VPS) but works on GPU (Colab)?
  2. Could preprocessing differences (e.g., resizing, normalization) cause this issue?
  3. Are there known compatibility issues with YOLOv8 on CPU-only setups?
  • Roboflow JSON Output:
    [
    {
    “count_objects”: 2,
    “predictions”: {
    “image”: {“width”: 827, “height”: 465},
    “predictions”: [
    {“class”: “next_button2”, “confidence”: 0.9457724690437317},
    {“class”: “email_field2”, “confidence”: 0.9373074173927307}
    ]
    }
    }
    ]

Screenshots for Reference:

All Test Images and Outputs: Imgur: The magic of the Internet

Hi @kozuki ,

In VPS code sample you are inferring using ultralytics, and this script seems to be producing incorrect result.
You also mentioned that workflows (through web interface) produced correct results.

When weights are trained we produce two artifacts, the pt file and also onnx file (as export from pt file). Both ultralytics as well as inference packages should produce the same result. I’d encourage trying inference package to see if it will produce correct results on your VPS.

Many thanks,
Grzegorz