简体   繁体   English

ImageAI 目标检测非常慢

[英]ImageAI Object Detection Very Slow

I have been attempting to make a program that can identify objects on my screen using python.我一直在尝试制作一个可以使用 python 识别屏幕上对象的程序。 With the help of this tutorial: https://stackabuse.com/object-detection-with-imageai-in-python , I have created the following code.在本教程的帮助下: 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))

I would like to be able to achieve 20-30 fps, however, I can only get around 1 fps and I do not know what is slowing it down.我希望能够达到 20-30 fps,但是,我只能达到 1 fps 左右,我不知道是什么让它变慢了。

My specs are:我的规格是:

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

All help is greatly appreciated.非常感谢所有帮助。

Is the program using your CPU or GPU?该程序使用的是您的 CPU 还是 GPU? If it uses the CPU, you might wanna check that you have the right version of tensorflow-gpu installed (if at all).如果它使用 CPU,您可能需要检查是否安装了正确版本的 tensorflow-gpu(如果有的话)。 ImageAI will prefer your GPU if it has access to it, but 20-30fps is pretty much impossible with it - too inefficient.如果 ImageAI 可以访问它,它会更喜欢你的 GPU,但是 20-30fps 几乎是不可能的——效率太低了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM