Python 3.x 如何使用.mat数据集或S3文件夹的图像批量测试Sagemaker对象检测模型?

Python 3.x 如何使用.mat数据集或S3文件夹的图像批量测试Sagemaker对象检测模型?,python-3.x,amazon-web-services,amazon-s3,mat,amazon-sagemaker,Python 3.x,Amazon Web Services,Amazon S3,Mat,Amazon Sagemaker,我培训了以下Sagemaker模型: 我尝试了JSON和RecordIO版本。在这两种算法中,算法都在一幅样本图像上进行了测试。然而,我有一个2000张图片的数据集,我想测试一下。我已经将2000张jpg图片保存在S3存储桶中的一个文件夹中,我还有两个.mat文件(pics+ground truth)。如何一次将此模型应用于所有2000张图片,然后保存结果,而不是一次只保存一张图片 我正在使用下面的代码从S3存储桶中加载一张图片: object = bucket.Object('pictures

我培训了以下Sagemaker模型:

我尝试了JSON和RecordIO版本。在这两种算法中,算法都在一幅样本图像上进行了测试。然而,我有一个2000张图片的数据集,我想测试一下。我已经将2000张jpg图片保存在S3存储桶中的一个文件夹中,我还有两个.mat文件(pics+ground truth)。如何一次将此模型应用于所有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'])

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

代码看起来像这样

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张图像中对它们进行批处理并预测

谢谢大家!!这就是我要找的!