我一直试图制作一个程序,它可以使用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,我不知道是什么减慢了它。
我的规格是:
我们非常感谢所有的帮助。
发布于 2022-07-19 14:39:21
程序是使用您的CPU还是GPU?如果它使用CPU,您可能需要检查是否安装了tensorflow-gpu的正确版本(如果有的话)。ImageAI会更喜欢你的GPU,如果它有它的访问,但20-30 GPU几乎是不可能的-太低效率。
https://stackoverflow.com/questions/68433103
复制相似问题