# Class Detection Issue with YOLOv8 Model - Inconsistent Results Across Environments

**URL:** <https://discuss.roboflow.com/t/class-detection-issue-with-yolov8-model-inconsistent-results-across-environments/8837>\
**Category:** 🤝  Community Help\
**Tags:** bugs\
**Created:** [March 1, 2025, 1:14pm UTC](https://discuss.roboflow.com/t/class-detection-issue-with-yolov8-model-inconsistent-results-across-environments/8837 "2025-03-01T13:14:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kozuki](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@kozuki](https://discuss.roboflow.com/u/kozuki)\
**Post date:** [March 1, 2025, 1:14pm UTC](https://discuss.roboflow.com/t/class-detection-issue-with-yolov8-model-inconsistent-results-across-environments/8837/1 "2025-03-01T13:14:51Z")

</div>

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):**

```auto
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:**

```auto
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`):**

```auto
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** :

```auto
[{"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](https://app.roboflow.com/workflows/embed/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3b3JrZmxvd0lkIjoiSGdidXRodTFoNUZQckE1bWo2TXYiLCJ3b3Jrc3BhY2VJZCI6IlEzU1paTU9aWVdkWmtUcjlWMVZBcURhWllwNDMiLCJ1c2VySWQiOiJRM1NaWk1PWllXZFprVHI5VjFWQXFEYVpZcDQzIiwiaWF0IjoxNzQwODMzMjc5fQ.TtKjEYgIYOfFHW5iUP2mrkDSJLcLzslcR0kxGNU6I8c)

**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](https://imgur.com/a/0ikKyes)

---

<div class="post-metadata">

**Author:** ![Grzegorz](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/grzegorz/32/2877_2.png) [@Grzegorz](https://discuss.roboflow.com/u/Grzegorz)\
**Post date:** [March 3, 2025, 12:21pm UTC](https://discuss.roboflow.com/t/class-detection-issue-with-yolov8-model-inconsistent-results-across-environments/8837/2 "2025-03-03T12:21:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [March 24, 2025, 12:22pm UTC](https://discuss.roboflow.com/t/class-detection-issue-with-yolov8-model-inconsistent-results-across-environments/8837/3 "2025-03-24T12:22:51Z")

</div>

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