【发布时间】: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