作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Q2)如何从S3下载文件?
来自 The Machine Learning Workflow with SageMaker
我们为什么要使用这段代码?
estimator.fit(train_data_location)
最佳答案
Q2 部分中的此代码块定义了从 S3 下载文件的函数。用户实例化 S3 客户端,然后将 S3 URL 传递给 s3.Bucket.download_file()
方法。
def download_from_s3(url):
"""ex: url = s3://sagemakerbucketname/data/validation.tfrecords"""
url_parts = url.split("/") # => ['s3:', '', 'sagemakerbucketname', 'data', ...
bucket_name = url_parts[2]
key = os.path.join(*url_parts[3:])
filename = url_parts[-1]
if not os.path.exists(filename):
try:
# Create an S3 client
s3 = boto3.resource('s3')
print('Downloading {} to {}'.format(url, filename))
s3.Bucket(bucket_name).download_file(key, filename)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
print('The object {} does not exist in bucket {}'.format(
key, bucket_name))
else:
raise
estimator.fit(train_data_location)
行用于启动 SageMaker 的训练过程。运行时,SageMaker 将配置必要的基础设施,从用户指定的位置(此处为 train_data_location
,这是 Amazon S3 的路径)获取数据,并将其分发到训练集群中,执行训练处理,返回结果模型,并拆除训练基础设施。
您可以在 SageMaker 控制台中找到此训练作业的结果。
关于python - 在这篇博文中,S3 文件下载和 estimator.fit() 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58018893/
我是一名优秀的程序员,十分优秀!