Converted Model Accuracy Issue

I found the problem, the input color needs to be converted, im using
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

so I when i was looking for an inference script, I came across this topic , then I modified the script a bit, I tested the HAR file and it worked flawlessly, then i noticed the color conversion, took me 5 weeks to figure this out…

here’s my host machine inference script if anyone’s interested

import os
import cv2
import numpy as np
from hailo_sdk_client import ClientRunner,InferenceContext

img_w = 1024
img_h = 1024

count = 0
validation_image_path = ‘validation_images/logo_detector_v1’
inference_result_path = ‘host_infer_result/logo-detector_yolov8s’
for file in os.listdir(validation_image_path):
if file.lower().endswith(‘.jpg’):
count+=1
print(f’processing image {count}')
img = cv2.imread(os.path.join(validation_image_path, file), cv2.IMREAD_COLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# img = img / 255.0
img = img.astype(np.float32)
img = np.array([img])

    model_name = "logo-detector_yolov8s"
    har_path = f"har_files/{model_name}_quantized_model.har"
    runner = ClientRunner(har=har_path)

    with runner.infer_context(InferenceContext.SDK_QUANTIZED) as ctx:
        output = runner.infer(ctx, np.array(img))
    xmin = int(output[0][0][1][0] * img_w)
    ymin = int(output[0][0][0][0] * img_h)
    xmax = int(output[0][0][3][0] * img_w)
    ymax = int(output[0][0][2][0] * img_h)

    img = img[0]
    img = (img * 255).astype(np.uint8)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    img = cv2.bitwise_not(img)
    img = cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (255,0,0), thickness=2)

    print(img.shape, img.dtype)

    if not cv2.imwrite(f"{inference_result_path}/result{count}.jpg",img):
        raise Exception("image not written")
1 Like