如何在 GPU 上使用子进程进行批量推理?

时间:2021-02-14 03:54:48

标签: python tensorflow computer-vision object-detection yolo

我正在使用 YOLOv4 在 Colab 上训练对象检测模型。这是我用来在测试集上运行测试的:

#/test has images that we can test our detector on
test_folder = "/content/logorec/Worlds-2020-Logos/"
test_images = [f for f in os.listdir(test_folder) if f.endswith('.png')]
import random
img_path = ''

for i in range(0, len(test_images)):
  img_path = test_folder + test_images[i];
  !./darknet detect cfg/custom-yolov4-detector.cfg backup/custom-yolov4-detector_last.weights {img_path} -dont-show
  imShow('predictions.jpg')

如您所见,问题在于它一次测试 1 个文件。对于非常大的测试集来说,这是非常低效的。有没有办法可以批量(同时)而不是按顺序运行推理?我目前可以使用 Tesla V100 GPU。

1 个答案:

答案 0 :(得分:0)

是的,你可以。您必须通过路径将所有测试图像加载到 tf.dataset.Dataset 对象中。我不知道你从哪里得到 YoloV4,但我认为它必须提供一个函数来一次读取整个数据集对象。尝试打开文件 darknet 以找到它

相关问题