我安装了 tensorflow 2.0 -gpu。我正在使用 MTCNN 进行人脸检测。第一次检测人脸需要 3.86 秒。在下一次通话中,只需 0.049 秒。我怀疑它在第一次调用时没有使用 GPU,但在第二次调用时使用了 GPU。我知道 MTCNN 确实导入了 tensorflow,但我不明白为什么第一次调用时不使用 GPU。代码如下。
import time
from mtcnn import MTCNN
import cv2
#********first run of image detection - note resulting process time- think not using gpu
detector = MTCNN()
img_file=r'c:\Temp\people\storage\1.jpg'
img = cv2.imread(img_file, cv2.COLOR_BGR2RGB)
start=time.time()
detector.detect_faces(img)
stop=time.time()
duration = stop-start
print(duration)
# rerun image detection on the same image - note duration much less must be using gpu
start=time.time()
detector.detect_faces(img)
stop=time.time()
duration = stop-start
print(duration)
Using TensorFlow backend.
3.8625590801239014
0.049181222915649414