ImageAI 对象检测非常慢

问题描述

我一直在尝试制作一个可以使用 python 识别屏幕上对象的程序。借助本教程:https://stackabuse.com/object-detection-with-imageai-in-python,我创建了以下代码

import pyautogui
import cv2
import time
import os

os.add_dll_directory("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/bin")

from imageai.Detection import ObjectDetection
import tensorflow as tf

detector = ObjectDetection()

model_path = "./models/yolo-tiny.h5"
input_path = "./input/test45.jpg"
output_path = "./output/newimage.jpg"

detector.setModelTypeAsTinyYOlov3()
detector.setModelPath(model_path)
detector.loadModel(detection_speed="fastest")
while True:
    start_time = time.time()
    x = np.array(pyautogui.screenshot())
    x = cv2.cvtColor(x,cv2.COLOR_BGR2RGB)
    y,detection = detector.detectObjectsFromImage(input_type="array",input_image=x,output_type="array")
    for eachItem in detection:
        print(eachItem["name"]," : ",eachItem["percentage_probability"])
    print("FPS: ",1.0 / (time.time() - start_time))

我希望能够达到 20-30 fps,但是,我只能达到 1 fps,我不知道是什么让它变慢了。

我的规格是:

  • 2 个 RTX 3060
  • 英特尔 i7 4770
  • 24GB 内存

非常感谢所有帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)