Skip to content

cv2.remap slows down the model inference  #24452

@bigsausage

Description

@bigsausage

System Information

python version 3.9.6
cv2 version 4.8.0

Detailed description

i find that the inference time of yolo model would be slow down when i use cv2.remap to the image

Steps to reproduce

t0_total = 0
t1_total = 0
t2_total = 0
t0_point = 100
t1_point = 200
t2_point = 300
for i in range(t2_point+1):
    img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
    torch.cuda.synchronize()
    t = time.time()
    results = model.predict(source=img, show=False, imgsz=640, device=0)
    torch.cuda.synchronize()
    if i < t0_point:
        t0_total += time.time()-t
    elif i< t1_point:
        t1_total += time.time()-t
    else:
        t2_total += time.time()-t

print("avg t0 time",t0_total/t0_point)
print("avg t1 time",t1_total/(t1_point - t0_point -1))
print("avg t2 time",t2_total/(t2_point - t1_point -1))

the model is yolov8 model

when i run this code , i get the result as

avg t0 time 0.012496998310089111
avg t1 time 0.016826453835073144
avg t2 time 0.029507776703497374

but without the line img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) i got :

avg t0 time 0.013513808250427245
avg t1 time 0.013428420731515595
avg t2 time 0.013519821744976622

so i'm confused why the remap operation would affect the yolov8 inference?
i supose that cv2 operates on cpu and my yolov8 model inference on gpu, is it the data tranport thing or the multi-thread thing,
i'm so confused

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    question (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.org

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions