【问题标题】:How to bulk test the Sagemaker Object detection model with a .mat dataset or S3 folder of images?如何使用 .mat 数据集或 S3 图像文件夹批量测试 Sagemaker 对象检测模型?
【发布时间】:2019-03-23 09:23:58
【问题描述】:

我已经训练了以下 Sagemaker 模型:https://github.com/awslabs/amazon-sagemaker-examples/tree/master/introduction_to_amazon_algorithms/object_detection_pascalvoc_coco

我已经尝试过 JSON 和 RecordIO 版本。在这两种情况下,算法都在一张样本图像上进行测试。但是,我有一个包含 2000 张图片的数据集,我想对其进行测试。我已将 2000 张 jpg 图片保存在 S3 存储桶内的文件夹中,并且我还有两个 .mat 文件(图片 + 基本事实)。我怎样才能一次将此模型应用于所有 2000 张图片,然后保存结果,而不是一次只做一张图片?

我正在使用下面的代码从我的 S3 存储桶中加载单张图片:

object = bucket.Object('pictures/pic1.jpg')
object.download_file('pic1.jpg')
img=mpimg.imread('pic1.jpg')
img_name = 'pic1.jpg'
imgplot = plt.imshow(img)
plt.show(imgplot)

with open(img_name, 'rb') as image:
    f = image.read()
    b = bytearray(f)
    ne = open('n.txt','wb')
    ne.write(b)

import json
object_detector.content_type = 'image/jpeg'
results = object_detector.predict(b)
detections = json.loads(results)
print (detections['prediction'])

【问题讨论】:

    标签: python-3.x amazon-web-services amazon-s3 mat amazon-sagemaker


    【解决方案1】:

    我不确定我是否正确理解了您的问题。但是,如果您想一次向模型提供多个图像,您可以创建一个多维图像数组(字节数组)来提供模型。

    代码看起来像这样。

    import numpy as np
    ...
    
    #  predict_images_list is a Python list of byte arrays
    predict_images = np.stack(predict_images_list)
    
    with graph.as_default():
        #  results is an list of typical results you'd get.
        results = object_detector.predict(predict_images)
    

    但是,我不确定一次输入 2000 张图像是否是个好主意。最好一次批量处理 20-30 张图像并进行预测。

    【讨论】:

    • 谢谢!这就是我要找的东西!
    猜你喜欢
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 2019-06-09
    • 2021-09-21
    • 2023-03-25
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    相关资源
    最近更新 更多