ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
27.63k stars 5.5k forks source link

Why the reasoning speed of yolov8-seg is getting slower and slower? #14480

Open fjk123456 opened 1 month ago

fjk123456 commented 1 month ago

Search before asking

Question

Why the reasoning speed of yolov8-seg is getting slower and slower? The average processing and inference time of the first half of the video is 100ms, and the second half suddenly becomes 200ms, sometimes even 500ms. Is it that resources have not been released? Or is there something wrong with me using it like this? ` def capture_video(cap, q, skip_frame=0): cnt = 0 while True: ret = cap.grab() if not ret: break cnt += 1 if skip_frame > 0: if cnt % skip_frame == 0: cnt = 0 ret, frame = cap.retrieve() if ret: q.put(frame) else: ret, frame = cap.retrieve() if ret: q.put(frame) cap.release()

def detect_img(q, model, out): cnt = 0 first_round = False is_drawed = False limit_obj = LIMIT_NUM_OBJ(5) while True: if not q.empty(): cnt = 0 first_round = True

从队列中获取帧

        frame = q.get()
        result = model.predict(frame, conf=0.45, imgsz=1280)
        out.write(result)

    else:
        if cnt > 10:
            break
        cnt += 1

capture_thread = threading.Thread(target=capture_video, args=(cap, q)) show_thread = threading.Thread(target=detect_img, args=(q, yolov8, out)) capture_thread.start() show_thread.start()

# 等待线程结束
capture_thread.join()
show_thread.join()

out.release()
cap.release()

`

Additional

No response

github-actions[bot] commented 1 month ago

👋 Hello @fjk123456, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Y-T-G commented 1 month ago

What's out?

fjk123456 commented 1 month ago

What's out? I don't know, either. I just want to ask what went wrong, or the way to predict video or rtsp stream in this way is wrong. Is there any other more elegant and convenient method?

Henry0528 commented 1 month ago

I've met the same problem when detecting single images. The detection speed was around 20ms per image at first and became slower to about 200+ms per images. Here is my code for prediction: image

Henry0528 commented 1 month ago

I've met the same problem when detecting single images. The detection speed was around 20ms per image at first and became slower to about 200+ms per images. Here is my code for prediction: image

problem sovled. set stream=True and then put the result in a loop

fjk123456 commented 1 month ago

I set stream=True, but the time still hasn't changed. time

fjk123456 commented 1 month ago

I've met the same problem when detecting single images. The detection speed was around 20ms per image at first and became slower to about 200+ms per images. Here is my code for prediction: image

problem sovled. set stream=True and then put the result in a loop

I can't load the image, can you post a simple code snippet? How to put the result in a loop

Henry0528 commented 1 month ago

I've met the same problem when detecting single images. The detection speed was around 20ms per image at first and became slower to about 200+ms per images. Here is my code for prediction: image

problem sovled. set stream=True and then put the result in a loop

I can't load the image, can you post a simple code snippet? How to put the result in a loop

just as the code I've put, set the root to the folder you put the images, after that add the following code to put the result in a loop: for i in results: pass

fjk123456 commented 1 month ago

This problem has not been solved yet. I wonder if it is possible that the temperature is rising and the GPU frequency is down?