amazon-s3 - 如何将 OpenImages 从 Sage Maker 笔记本直接下载到 S3 存储桶?
问题描述
我正在使用openimages API下载在labels_array
. 此代码可轻松将所需的类下载到 Sage Maker 实例中的文件夹中。
from openimages.download import download_dataset
for labels in labels_array:
download_dataset(
data_location,
["{}".format(labels)],
annotation_format="pascal"
)
但我想将它下载到 S3 存储桶。我找到了这个解决方案示例:
boto3.Session().resource('s3').Bucket(bucket).Object(os.path.join('billing', 'billing_sm.csv')).upload_file('billing_sm.csv')
我无法弄清楚如何将此解决方案与 Sage Maker 上的 openimages API 一起使用。有人可以帮我理解这一点吗?
解决方案
在 Sage Maker 笔记本实例中创建一个 python 笔记本并使用以下代码。此代码将从 600 个打开的图像标签中下载所需标签的列表。一旦下载了一个类别,它就会被移动到 S3 存储桶并从笔记本实例中删除。
import os
import shutil
import openimages
from openimages.download import download_dataset
# create a directory where all the images will be downloaded in Sage Maker
os.mkdir('openImages/')
# create a list of the labels with either the first letter capital or all lowercase
labels_list = ["football","ambulance","ladder","toothbrush"]
# to download the list of labels to a S3 bucket
for labels in labels_list:
download_dataset("openImages/",
# remove `.capitalize()` if you have the first letter of label in uppercase
[labels.capitalize()],
annotation_format="pascal")
# to move the files from sage Maker to S3
os.system('aws s3 cp --recursive openImages/ s3://open-images/')
# remove the folder from Sage Maker once the files are copied to S3
shutil.rmtree("openImages/{}/".format(labels))
推荐阅读
- java - 在 Firebase Android 中选择查询
- kubernetes - 动态 URL 的 Kubernetes 入口
- django - 两个外键模型字段之间的区别
- ruby-on-rails - Doorkeeper gem 中的 previous_refresh_token 列如何工作?
- python - 在python中比较四个列表的一种更简单的方法
- python-3.x - 如何组合 2 个字符串列表并仅获得唯一值?
- azure - 使用 Play 框架时使用 Application Insights 启用 Web 请求日志记录
- python - 如何使用 python 从内联样式标签中删除特定的值对?
- python-sphinx - 狮身人面像超链接:打开反引号之前的非空格
- jetbrains-ide - 有没有办法从 Rider 中的 C# Interactive 访问当前的解决方案源?