参考tutorial.ipynb。我想知道是否可以运行目录中的所有图像。
而不是写一个for循环,运行一个“run_inference_for_single_image(图像,图形)”。是否有一种方法可以对目录中的所有图像运行推断,或者对多个图像运行推断。链接
for f in files:
if f.lower().endswith(('.png', '.jpg', '.jpeg')):
image_path = files_dir + '/' + f
.... // Read image etc.
output_dict = run_inference_for_single_image(image_np, detection_graph)这每次都会创建tf.session,我认为它的计算成本很高。如果我错了,请纠正我。
发布于 2018-07-25 07:35:17
我从google - creating-object-detection-application-tensorflow上找到了这个教程。在查看了它的github页面 --> 应用程序 --> app.py之后,我们只需要在每次检测对象时运行github页面函数。
发布于 2018-06-26 00:05:22
如您所知,“run_inference_for_single_image”方法每次都会创建。如果您想要对多个图像进行推断,您应该更改代码,
此代码将在每次只创建一次tf.session的情况下执行。
发布于 2018-10-11 06:11:23
根据GPU的计算能力和图像的大小,可以对批量图像进行推理。
步骤1:将所有测试图像堆叠在一个数组中:
for image_path in glob.glob(PATH_TO_TEST_IMAGES_DIR + '/*.jpg'):
image_np = io.imread(image_path) #
image_array.append(image_np)
image_array = np.array(image_array)步骤2:对批处理运行推断:(批大小越大可能导致内存不足)
BATCH_SIZE = 5
for i in range(0, image_array.shape[0],BATCH_SIZE):
output_dict = sess.run(tensor_dict, feed_dict={image_tensor: image_array[i:i+BATCH_SIZE]})
print("number of images inferenced = ", i+BATCH_SIZE)
output_dict_array.append(output_dict)确保image_tensor和image_array的尺寸匹配。在这个例子中,image_array是(?,高度,宽度,3)
一些小贴士:
https://stackoverflow.com/questions/49750520
复制相似问题