如何理解博客文章中S3文件下载和estimator.fit()的使用?

理解上的困难

Q2) 如何从S3下载文件?

来自 使用SageMaker的机器学习工作流程

另外,为什么我们要使用这段代码?

estimator.fit(train_data_location)


回答:

从S3下载文件:

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:            # 创建一个S3客户端            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()的解释:

estimator.fit(train_data_location)这一行代码启动了SageMaker的训练过程。运行时,SageMaker将配置必要的基础设施,从用户指定的位置(此处为train_data_location,即Amazon S3的路径)获取数据,并在训练集群中分发,执行训练过程,返回生成的模型,最后拆除训练基础设施。

您可以在SageMaker控制台中找到此训练作业的结果。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注